mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-09-03 06:24:26 -05:00
Implement Moods from the Funkey Trunk
This commit is contained in:
@@ -148,7 +148,10 @@ public class ArkOneController implements TcpHandler {
|
||||
responses.add(trunkPlugin.GetFamiliarsList());
|
||||
break;
|
||||
case "gjl":
|
||||
responses.add(trunkPlugin.GetJammerList());
|
||||
responses.add(trunkPlugin.GetJammersList());
|
||||
break;
|
||||
case "gml":
|
||||
responses.add(trunkPlugin.GetMoodsList());
|
||||
break;
|
||||
case "gutc":
|
||||
responses.add(trunkPlugin.GetUserTransactionsCount(connection));
|
||||
@@ -165,6 +168,9 @@ public class ArkOneController implements TcpHandler {
|
||||
case "bj":
|
||||
responses.add(trunkPlugin.BuyJammer(commandInfo, connection));
|
||||
break;
|
||||
case "bm":
|
||||
responses.add(trunkPlugin.BuyMood(commandInfo, connection));
|
||||
break;
|
||||
|
||||
// Catch Unhandled Commands
|
||||
default:
|
||||
|
||||
@@ -4,11 +4,9 @@ import com.icedberries.UBFunkeysServer.ArkOne.ArkOneParser;
|
||||
import com.icedberries.UBFunkeysServer.DatabaseSetup.TrunkData;
|
||||
import com.icedberries.UBFunkeysServer.domain.Familiar;
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import com.icedberries.UBFunkeysServer.domain.Mood;
|
||||
import com.icedberries.UBFunkeysServer.domain.User;
|
||||
import com.icedberries.UBFunkeysServer.service.FamiliarService;
|
||||
import com.icedberries.UBFunkeysServer.service.FileService;
|
||||
import com.icedberries.UBFunkeysServer.service.JammerService;
|
||||
import com.icedberries.UBFunkeysServer.service.UserService;
|
||||
import com.icedberries.UBFunkeysServer.service.*;
|
||||
import javagrinko.spring.tcp.Connection;
|
||||
import javagrinko.spring.tcp.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -38,7 +36,8 @@ public class TrunkPlugin {
|
||||
|
||||
private enum PurchaseType {
|
||||
FAMILIAR,
|
||||
JAMMER
|
||||
JAMMER,
|
||||
MOOD
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -53,12 +52,14 @@ public class TrunkPlugin {
|
||||
@Autowired
|
||||
JammerService jammerService;
|
||||
|
||||
@Autowired
|
||||
MoodService moodService;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
public String GetUserAssets(Connection connection) throws ParserConfigurationException, IOException, SAXException {
|
||||
//TODO: IMPLEMENT ITEMS | MOODS
|
||||
// Moods - Tag looks like this: <m id="80041a" />
|
||||
//TODO: IMPLEMENT ITEMS | CLEANING STATIONS | ROOMS
|
||||
|
||||
// Append the starting tags
|
||||
StringBuilder response = new StringBuilder();
|
||||
@@ -106,6 +107,17 @@ public class TrunkPlugin {
|
||||
if (c > 0) {
|
||||
response.append("<j id=\"" + TrunkData.JAMMER_RID + "\" p=\"" + p + "\" c=\"" + c + "\" />");
|
||||
}
|
||||
|
||||
// Append the moods
|
||||
Node moodParentNode = ArkOneParser.findParentNodeOfPath(profile.getChildNodes(), "profile/trunk/moods");
|
||||
for (int i = 0; i < moodParentNode.getChildNodes().getLength(); i++) {
|
||||
Element child = (Element) moodParentNode.getChildNodes().item(i);
|
||||
|
||||
String id = child.getAttribute("id");
|
||||
|
||||
// id -> item id
|
||||
response.append("<m id=\"" + id + "\" />");
|
||||
}
|
||||
}
|
||||
|
||||
// Append the ending tags
|
||||
@@ -142,7 +154,7 @@ public class TrunkPlugin {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String GetJammerList() {
|
||||
public String GetJammersList() {
|
||||
|
||||
// Get all the jammers
|
||||
List<Jammer> jammers = jammerService.findAll();
|
||||
@@ -151,7 +163,7 @@ public class TrunkPlugin {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<h10_0><gjl>");
|
||||
|
||||
// Iterate over the items in the familiars list to add them to the response
|
||||
// Iterate over the items in the jammers list to add them to the response
|
||||
for (Jammer jammer : jammers) {
|
||||
stringBuilder.append("<j rid=\"" + jammer.getRid() + "\" id=\"" + jammer.getId() + "\" c=\""
|
||||
+ jammer.getCost() + "\" q=\"" + jammer.getQty() + "\" d=\"\" />");
|
||||
@@ -164,6 +176,28 @@ public class TrunkPlugin {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String GetMoodsList() {
|
||||
|
||||
// Get all the moods
|
||||
List<Mood> moods = moodService.findAll();
|
||||
|
||||
// Start to build the response
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<h10_0><gml>");
|
||||
|
||||
// Iterate over the items in the moods list to add them to the response
|
||||
for (Mood mood : moods) {
|
||||
stringBuilder.append("<m rid=\"" + mood.getRid() + "\" id=\"" + mood.getId() + "\" c=\""
|
||||
+ mood.getCost() + "\" q=\"1\" d=\"\" />");
|
||||
}
|
||||
|
||||
// Add closing tags
|
||||
stringBuilder.append("</gml></h10_0>");
|
||||
|
||||
// Return the list
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String GetUserTransactionsCount(Connection connection) {
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
|
||||
@@ -240,6 +274,14 @@ public class TrunkPlugin {
|
||||
return "<h10_0><bj id=\"" + element.getAttribute("id") + "\" b=\"" + LOOT_BALANCE + "\" /></h10_0>";
|
||||
}
|
||||
|
||||
public String BuyMood(Element element, Connection connection) {
|
||||
// Save this transaction to the DB
|
||||
PostTransaction(connection, PurchaseType.MOOD, Integer.valueOf(element.getAttribute("id")));
|
||||
|
||||
// We always return LOOT_BALANCE so players are never charged for these items
|
||||
return "<h10_0><bm id=\"" + element.getAttribute("id") + "\" b=\"" + LOOT_BALANCE + "\" /></h10_0>";
|
||||
}
|
||||
|
||||
public void PostTransaction(Connection connection, PurchaseType purchaseType, Integer itemId) {
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
|
||||
@@ -257,6 +299,9 @@ public class TrunkPlugin {
|
||||
case JAMMER:
|
||||
cost = jammerService.getCostById(itemId);
|
||||
break;
|
||||
case MOOD:
|
||||
cost = moodService.getCostById(itemId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the rid of the item
|
||||
@@ -268,6 +313,9 @@ public class TrunkPlugin {
|
||||
case JAMMER:
|
||||
rid = jammerService.getRidById(itemId);
|
||||
break;
|
||||
case MOOD:
|
||||
rid = moodService.getRidById(itemId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Create a transaction xml tag
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.icedberries.UBFunkeysServer.DatabaseSetup;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Familiar;
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import com.icedberries.UBFunkeysServer.domain.Mood;
|
||||
import com.icedberries.UBFunkeysServer.service.FamiliarService;
|
||||
import com.icedberries.UBFunkeysServer.service.JammerService;
|
||||
import com.icedberries.UBFunkeysServer.service.MoodService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -21,26 +23,27 @@ public class TrunkData {
|
||||
@Autowired
|
||||
JammerService jammerService;
|
||||
|
||||
// List of all familiar ids
|
||||
@Autowired
|
||||
MoodService moodService;
|
||||
|
||||
// Familiars
|
||||
private final List<String> familiarIds = Arrays.asList("80036a", "80035a", "80034a", "80033a", "80032a", "80031a", "80030a",
|
||||
"80029a", "80028a", "80027a", "80026a", "80025a", "80017a", "80016a", "80015a", "80007a", "80006a",
|
||||
"80005a", "80004a", "80003a", "80002a", "80001a", "80000a");
|
||||
|
||||
public static final String JAMMER_RID = "80014a";
|
||||
private final List<Integer> JAMMER_PACKAGE_QTYS = Arrays.asList(1, 5, 10, 25, 50, 100);
|
||||
String PackageOf1 = "<j id=\"1\" rid=\"80014a\" c=\"10\" q=\"1\" d=\"\" />";
|
||||
String PackageOf5 = "<j id=\"2\" rid=\"80014a\" c=\"50\" q=\"5\" d=\"\" />";
|
||||
String PackageOf10 = "<j id=\"3\" rid=\"80014a\" c=\"100\" q=\"10\" d=\"\" />";
|
||||
String PackageOf25 = "<j id=\"4\" rid=\"80014a\" c=\"250\" q=\"25\" d=\"\" />";
|
||||
String PackageOf50 = "<j id=\"5\" rid=\"80014a\" c=\"500\" q=\"50\" d=\"\" />";
|
||||
String PackageOf100 = "<j id=\"6\" rid=\"80014a\" c=\"1000\" q=\"100\" d=\"\" />";
|
||||
|
||||
private final Integer JAMMER_COST = 10;
|
||||
|
||||
private final Integer FAMILIAR_COST = 100;
|
||||
private final Integer FAMILIAR_DISCOUNT_COST = 50;
|
||||
private final Integer FAMILIAR_DURATION = 720;
|
||||
|
||||
// Jammers
|
||||
private final List<Integer> JAMMER_PACKAGE_QTYS = Arrays.asList(1, 5, 10, 25, 50, 100);
|
||||
private final Integer JAMMER_COST = 10;
|
||||
|
||||
// Moods
|
||||
private final List<String> moodIds = Arrays.asList("80041a", "80040a", "80039a", "80038a", "80037a", "80024a", "80023a",
|
||||
"80022a", "80021a", "80020a", "80019a", "80018a", "80013a", "80012a", "80011a", "80010a", "80009a", "80008a");
|
||||
private final Integer MOOD_COST = 100;
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void insertFamiliars() {
|
||||
// Iterate over the familiar ids
|
||||
@@ -95,4 +98,30 @@ public class TrunkData {
|
||||
idNum++;
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void insertMoods() {
|
||||
// Iterate over the mood ids
|
||||
int idNum = 0;
|
||||
for (String id : moodIds) {
|
||||
// Attempt to get from the DB
|
||||
Mood mood = moodService.findByRid(id).orElse(null);
|
||||
|
||||
// Only insert if the data is null
|
||||
if (mood == null) {
|
||||
// Build a new mood to insert
|
||||
Mood newMood = Mood.builder()
|
||||
.id(idNum)
|
||||
.rid(id)
|
||||
.cost(MOOD_COST)
|
||||
.build();
|
||||
|
||||
// Save it to the db
|
||||
moodService.save(newMood);
|
||||
}
|
||||
|
||||
// Increment id
|
||||
idNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.icedberries.UBFunkeysServer.domain;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Moods")
|
||||
public class Mood {
|
||||
|
||||
// DB ID
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
// Item ID
|
||||
private String rid;
|
||||
|
||||
private Integer cost;
|
||||
|
||||
//private Integer qty;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.icedberries.UBFunkeysServer.repository;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Mood;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface MoodRepository extends CrudRepository<Mood, Integer> {
|
||||
|
||||
List<Mood> findAll();
|
||||
|
||||
@Query("select mood from Mood mood where mood.rid = :rid")
|
||||
Optional<Mood> findByRid(@Param("rid") String rid);
|
||||
|
||||
@Query("select mood.cost from Mood mood where mood.id = :id")
|
||||
Integer getCostById(@Param("id") Integer id);
|
||||
|
||||
@Query("select mood.rid from Mood mood where mood.id = :id")
|
||||
String getRidById(@Param("id") Integer id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.icedberries.UBFunkeysServer.service;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Mood;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface MoodService {
|
||||
|
||||
List<Mood> findAll();
|
||||
|
||||
Mood save(Mood mood);
|
||||
|
||||
Optional<Mood> findByRid(String rid);
|
||||
|
||||
Integer getCostById(Integer id);
|
||||
|
||||
String getRidById(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.icedberries.UBFunkeysServer.service.impl;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Mood;
|
||||
import com.icedberries.UBFunkeysServer.repository.MoodRepository;
|
||||
import com.icedberries.UBFunkeysServer.service.MoodService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MoodServiceImpl implements MoodService {
|
||||
|
||||
private final MoodRepository moodRepository;
|
||||
|
||||
public List<Mood> findAll() {
|
||||
return moodRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mood save(Mood mood) {
|
||||
return moodRepository.save(mood);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Mood> findByRid(String rid) {
|
||||
return moodRepository.findByRid(rid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCostById(Integer id) {
|
||||
return moodRepository.getCostById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRidById(Integer id) {
|
||||
return moodRepository.getRidById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user