-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new config plugin for AI spiders (Part 1)
- Loading branch information
1 parent
712c3ef
commit 3ea24c6
Showing
4 changed files
with
454 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
/** | ||
* | ||
*/ | ||
public class DataSkeletonDropItem | ||
public final class DataSkeletonDropItem | ||
{ | ||
/** | ||
* | ||
|
197 changes: 197 additions & 0 deletions
197
...org/imesense/dynamicspawncontrol/technical/config/spiderattackweb/CfgSpiderAttackWeb.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
package org.imesense.dynamicspawncontrol.technical.config.spiderattackweb; | ||
|
||
import com.google.gson.*; | ||
import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils; | ||
import org.imesense.dynamicspawncontrol.technical.config.CfgClassAbstract; | ||
import org.imesense.dynamicspawncontrol.technical.config.player.DataPlayer; | ||
import org.imesense.dynamicspawncontrol.technical.config.skeletondropitem.DataSkeletonDropItem; | ||
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log; | ||
import org.imesense.dynamicspawncontrol.technical.customlibrary.inlineannotations.DCSSingleConfig; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* | ||
*/ | ||
@DCSSingleConfig(fileName = "cfg_plugin_spider_attack_web.json") | ||
public final class CfgSpiderAttackWeb extends CfgClassAbstract | ||
{ | ||
/** | ||
* | ||
* @param nameConfigFile | ||
*/ | ||
public CfgSpiderAttackWeb(String nameConfigFile) | ||
{ | ||
super(nameConfigFile); | ||
|
||
CodeGenericUtils.printInitClassToLog(this.getClass()); | ||
|
||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance = | ||
new DataSpiderAttackWeb.ConfigDataSpiderAttackWeb("spider_web_attack"); | ||
|
||
if (Files.exists(Paths.get(this.nameConfig))) | ||
{ | ||
this.loadFromFile(); | ||
} | ||
else | ||
{ | ||
this.saveToFile(); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public void saveToFile() | ||
{ | ||
Path configPath = Paths.get(this.nameConfig).getParent(); | ||
|
||
if (Files.notExists(configPath)) | ||
{ | ||
try | ||
{ | ||
Files.createDirectories(configPath); | ||
} | ||
catch (IOException exception) | ||
{ | ||
throw new RuntimeException(exception); | ||
} | ||
} | ||
|
||
JsonObject recordObject = new JsonObject(); | ||
JsonObject jsonObjectWeb = new JsonObject(); | ||
|
||
jsonObjectWeb.addProperty("block_web_replacement", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getBlockWebReplacement()); | ||
|
||
jsonObjectWeb.addProperty("web_melee_chance", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getWebMeleeChance()); | ||
|
||
jsonObjectWeb.addProperty("sling_cooldown", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingCooldown()); | ||
|
||
jsonObjectWeb.addProperty("sling_inaccuracy", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingInaccuracy()); | ||
|
||
jsonObjectWeb.addProperty("sling_variance", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingVariance()); | ||
|
||
jsonObjectWeb.addProperty("sling_webbing", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingWebbing()); | ||
|
||
jsonObjectWeb.addProperty("sling_webbing_on_web", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getSlingWebbingOnWeb()); | ||
|
||
jsonObjectWeb.addProperty("ai_priority_sling_webs", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getAIPrioritySlingWebs()); | ||
|
||
jsonObjectWeb.addProperty("debug_info", | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getDebugInfo()); | ||
|
||
recordObject.add(DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getCategoryObject(), jsonObjectWeb); | ||
|
||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
|
||
try (FileWriter file = new FileWriter(this.nameConfig)) | ||
{ | ||
gson.toJson(recordObject, file); | ||
} | ||
catch (IOException exception) | ||
{ | ||
throw new RuntimeException("Error writing to file: " + exception.getMessage(), exception); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public void loadFromFile() | ||
{ | ||
try (FileReader fileReader = new FileReader(this.nameConfig)) | ||
{ | ||
JsonElement fileReaderJsonElement = new JsonParser().parse(fileReader); | ||
JsonObject readableObject = fileReaderJsonElement.getAsJsonObject(); | ||
|
||
if (readableObject.has(DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getCategoryObject())) | ||
{ | ||
JsonObject jsonObjectWeb = readableObject.getAsJsonObject( | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.getCategoryObject()); | ||
|
||
if (jsonObjectWeb.has("block_web_replacement")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setBlockWebReplacement( | ||
jsonObjectWeb.get("block_web_replacement").getAsBoolean()); | ||
} | ||
|
||
if (jsonObjectWeb.has("web_melee_chance")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setWebMeleeChance( | ||
jsonObjectWeb.get("web_melee_chance").getAsFloat()); | ||
} | ||
|
||
if (jsonObjectWeb.has("sling_cooldown")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setSlingCooldown( | ||
jsonObjectWeb.get("sling_cooldown").getAsInt()); | ||
} | ||
|
||
if (jsonObjectWeb.has("sling_inaccuracy")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setSlingInaccuracy( | ||
jsonObjectWeb.get("sling_inaccuracy").getAsFloat()); | ||
} | ||
|
||
if (jsonObjectWeb.has("sling_variance")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setSlingVariance( | ||
jsonObjectWeb.get("sling_variance").getAsFloat()); | ||
} | ||
|
||
if (jsonObjectWeb.has("sling_webbing")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setSlingWebbing( | ||
jsonObjectWeb.get("sling_webbing").getAsBoolean()); | ||
} | ||
|
||
if (jsonObjectWeb.has("sling_webbing_on_web")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setSlingWebbingOnWeb( | ||
jsonObjectWeb.get("sling_webbing_on_web").getAsBoolean()); | ||
} | ||
|
||
if (jsonObjectWeb.has("ai_priority_sling_webs")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setAIPrioritySlingWebs( | ||
jsonObjectWeb.get("ai_priority_sling_webs").getAsInt()); | ||
} | ||
|
||
if (jsonObjectWeb.has("debug_info")) | ||
{ | ||
DataSpiderAttackWeb.ConfigDataSpiderAttackWeb.instance.setDebugInfo( | ||
jsonObjectWeb.get("debug_info").getAsBoolean()); | ||
} | ||
} | ||
else | ||
{ | ||
Log.writeDataToLogFile(2, "'web' section is missing in the config file."); | ||
} | ||
} | ||
catch (FileNotFoundException exception) | ||
{ | ||
Log.writeDataToLogFile(2, "File not found: " + exception.getMessage()); | ||
} | ||
catch (IOException exception) | ||
{ | ||
Log.writeDataToLogFile(2, "IO Exception while loading: " + exception.getMessage()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.