Added profession template clothing loader and implemented it in CharacterCreation

This commit is contained in:
Obique
2019-02-09 14:39:18 -06:00
parent a6ccfe42bf
commit df29a10dae
4 changed files with 86 additions and 26 deletions
@@ -66,6 +66,10 @@ public abstract class DataLoader {
return getInstance(PlayerRoleLoader.class, PlayerRoleLoader::new);
}
public static StartClothingLoader playerStartClothing() {
return getInstance(StartClothingLoader.class, StartClothingLoader::new);
}
public static RoadmapRewardLoader roadmapRewards() {
return getInstance(RoadmapRewardLoader.class, RoadmapRewardLoader::new);
}
@@ -0,0 +1,71 @@
/***********************************************************************************
* Copyright (c) 2019 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.server_info.loader;
import com.projectswg.common.data.encodables.tangible.Race;
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader;
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader.SdbResultSet;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.*;
public final class StartClothingLoader extends DataLoader {
private final Map<Race, Map<String, List<String>>> clothing;
StartClothingLoader() {
this.clothing = new EnumMap<>(Race.class);
}
@Nullable
public List<String> getClothing(Race race, String clothingName) {
Map<String, List<String>> raceClothing = clothing.get(race);
if (raceClothing == null)
return null;
return raceClothing.get(clothingName);
}
@Override
public final void load() throws IOException {
try (SdbResultSet set = SdbLoader.load(new File("serverdata/player/start_clothing.sdb"))) {
List<String> columns = set.getColumns();
while (set.next()) {
Race race = Race.getRace(set.getText("race"));
Map<String, List<String>> clothingItems = new HashMap<>();
for (String clothingName : columns) {
if (clothingName.equals("race"))
continue;
clothingItems.put(clothingName, List.of(set.getText(clothingName).split(";")));
}
this.clothing.put(race, Collections.unmodifiableMap(clothingItems));
}
}
}
}
@@ -31,10 +31,10 @@ import com.projectswg.common.data.encodables.tangible.PvpFlag;
import com.projectswg.common.data.encodables.tangible.Race;
import com.projectswg.common.data.location.Location;
import com.projectswg.common.data.swgfile.ClientFactory;
import com.projectswg.common.data.swgfile.visitors.ProfTemplateData;
import com.projectswg.common.network.packets.swg.login.creation.ClientCreateCharacter;
import com.projectswg.holocore.intents.gameplay.player.experience.skills.GrantSkillIntent;
import com.projectswg.holocore.intents.support.objects.swg.ObjectCreatedIntent;
import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader;
import com.projectswg.holocore.resources.support.data.server_info.loader.TerrainZoneInsertionLoader.ZoneInsertion;
import com.projectswg.holocore.resources.support.global.player.AccessLevel;
import com.projectswg.holocore.resources.support.objects.ObjectCreator;
@@ -52,14 +52,13 @@ import me.joshlarson.jlcommon.utilities.Arguments;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
import java.util.List;
public class CharacterCreation {
private final ProfTemplateData templateData;
private final ClientCreateCharacter create;
public CharacterCreation(ProfTemplateData templateData, ClientCreateCharacter create) {
this.templateData = templateData;
public CharacterCreation(ClientCreateCharacter create) {
this.create = create;
}
@@ -71,7 +70,7 @@ public class CharacterCreation {
setCreatureObjectValues(creatureObj);
setPlayerObjectValues(playerObj);
createHair(creatureObj, create.getHair(), create.getHairCustomization());
createStarterClothing(creatureObj, create.getRace());
createStarterClothing(creatureObj, create.getRace(), create.getClothes());
playerObj.setAdminTag(accessLevel);
new ObjectCreatedIntent(creatureObj).broadcast();
return creatureObj;
@@ -169,9 +168,12 @@ public class CharacterCreation {
playerObj.setBornDate(Instant.now());
}
private void createStarterClothing(CreatureObject creature, String race) {
for (String template : templateData.getItems(ClientFactory.formatToSharedFile(race))) {
createDefaultObject(creature, template);
private void createStarterClothing(CreatureObject creature, String race, String clothing) {
List<String> items = DataLoader.playerStartClothing().getClothing(Race.getRace(race), clothing);
if (items != null) {
for (String itemTemplate : items) {
createDefaultObject(creature, itemTemplate);
}
}
SWGObject inventory = creature.getSlottedObject("inventory");
@@ -28,8 +28,6 @@ package com.projectswg.holocore.services.support.global.zone.creation;
import com.projectswg.common.data.encodables.mongo.MongoData;
import com.projectswg.common.data.encodables.tangible.Race;
import com.projectswg.common.data.swgfile.ClientFactory;
import com.projectswg.common.data.swgfile.visitors.ProfTemplateData;
import com.projectswg.common.network.packets.SWGPacket;
import com.projectswg.common.network.packets.swg.login.creation.*;
import com.projectswg.common.network.packets.swg.login.creation.ClientVerifyAndLockNameResponse.ErrorMessage;
@@ -63,12 +61,10 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
public class CharacterCreationService extends Service {
private final Map <String, Player> lockedNames;
private final Map <String, ProfTemplateData> profTemplates;
private final NameFilter nameFilter;
private final SWGNameGenerator nameGenerator;
private final CharacterCreationRestriction creationRestriction;
@@ -76,7 +72,6 @@ public class CharacterCreationService extends Service {
public CharacterCreationService() {
this.lockedNames = new HashMap<>();
this.profTemplates = new ConcurrentHashMap<>();
this.nameFilter = new NameFilter(getClass().getResourceAsStream("/namegen/bad_word_list.txt"), getClass().getResourceAsStream("/namegen/reserved_words.txt"), getClass().getResourceAsStream("/namegen/fiction_reserved.txt"));
this.nameGenerator = new SWGNameGenerator(nameFilter);
@@ -88,7 +83,6 @@ public class CharacterCreationService extends Service {
public boolean initialize() {
userDatabase.initialize();
nameGenerator.loadAllRules();
loadProfTemplates();
if (!nameFilter.load())
Log.e("Failed to load name filter!");
return super.initialize();
@@ -211,7 +205,6 @@ public class CharacterCreationService extends Service {
NameFailureReason reason = NameFailureReason.NAME_SYNTAX;
switch (err) {
case NAME_APPROVED:
err = ErrorMessage.NAME_DECLINED_INTERNAL_ERROR;
reason = NameFailureReason.NAME_RETRY;
break;
case NAME_DECLINED_FICTIONALLY_INAPPROPRIATE:
@@ -277,20 +270,10 @@ public class CharacterCreationService extends Service {
Log.e("Failed to get spawn information for location: " + spawnLocation);
return null;
}
CharacterCreation creation = new CharacterCreation(profTemplates.get(create.getClothes()), create);
CharacterCreation creation = new CharacterCreation(create);
return creation.createCharacter(player.getAccessLevel(), info);
}
private void loadProfTemplates() {
profTemplates.put("crafting_artisan", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_crafting_artisan.iff"));
profTemplates.put("combat_brawler", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_combat_brawler.iff"));
profTemplates.put("social_entertainer", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_social_entertainer.iff"));
profTemplates.put("combat_marksman", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_combat_marksman.iff"));
profTemplates.put("science_medic", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_science_medic.iff"));
profTemplates.put("outdoors_scout", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_outdoors_scout.iff"));
profTemplates.put("jedi", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_jedi.iff"));
}
private boolean lockName(String name, Player player) {
String firstName = name.split(" ", 2)[0].toLowerCase(Locale.ENGLISH);
if (isLocked(player, firstName))