Making Objective NPC's and other stuff
parent
38f3d9b7be
commit
0766b0eb9e
@ -0,0 +1,74 @@
|
|||||||
|
package com.zivilon.cinder_loe;
|
||||||
|
|
||||||
|
import lotr.common.LOTRLevelData;
|
||||||
|
import lotr.common.entity.npc.LOTRBannerBearer;
|
||||||
|
import lotr.common.entity.npc.LOTRHireableBase;
|
||||||
|
import lotr.common.entity.npc.LOTRUnitTradeEntry;
|
||||||
|
import lotr.common.fac.LOTRFaction;
|
||||||
|
import lotr.common.item.LOTRItemCoin;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.StatCollector;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class CinderUnitTradeEntry extends LOTRUnitTradeEntry {
|
||||||
|
|
||||||
|
public Class entityClass;
|
||||||
|
private String name;
|
||||||
|
private PledgeType pledgeType = PledgeType.NONE;
|
||||||
|
private String objectivename;
|
||||||
|
private static Configuration config;
|
||||||
|
|
||||||
|
static {
|
||||||
|
config = new Configuration(new File("CinderLoE.cfg"));
|
||||||
|
config.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CinderUnitTradeEntry(Class c, int cost, float alignment) {
|
||||||
|
super(c, cost, alignment);
|
||||||
|
this.entityClass = c; // Set entityClass to the passed class
|
||||||
|
|
||||||
|
if (LOTRBannerBearer.class.isAssignableFrom(this.entityClass)) {
|
||||||
|
this.setExtraInfo("Banner");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CinderUnitTradeEntry(Class c, Class c1, String s, int cost, float alignment) {
|
||||||
|
super(c, cost, alignment);
|
||||||
|
this.entityClass = c; // Set entityClass to the passed class
|
||||||
|
this.mountClass = c1;
|
||||||
|
this.name = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isObjectiveComplete(String objective) {
|
||||||
|
return config.getBoolean(objective, Configuration.CATEGORY_GENERAL, false, "Set true if " + objective + " is complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasRequiredCostAndAlignment(EntityPlayer entityplayer, LOTRHireableBase trader) {
|
||||||
|
int coins = LOTRItemCoin.getInventoryValue(entityplayer, false);
|
||||||
|
if (coins < this.getCost(entityplayer, trader)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LOTRFaction fac = trader.getFaction();
|
||||||
|
if (!this.pledgeType.canAcceptPlayer(entityplayer, fac)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (objectivename != null && !isObjectiveComplete(objectivename)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
float alignment = LOTRLevelData.getData(entityplayer).getAlignment(fac);
|
||||||
|
return alignment >= this.alignmentRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CinderUnitTradeEntry setObjective(String objective) {
|
||||||
|
this.objectivename = objective;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedExtraInfo() {
|
||||||
|
return StatCollector.translateToLocal((String) "lotr.unitinfo." + this.objectivename);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,9 +0,0 @@
|
|||||||
package com.zivilon.cinder_loe.mixins.overrides;
|
|
||||||
|
|
||||||
import lotr.common.entity.npc.LOTRUnitTradeEntry;
|
|
||||||
|
|
||||||
public interface ILOTRUnitTradeEntry {
|
|
||||||
LOTRUnitTradeEntry setObjective(String objectiveKey);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
package com.zivilon.cinder_loe.mixins.overrides;
|
|
||||||
|
|
||||||
import lotr.common.entity.npc.LOTRHireableBase;
|
|
||||||
import lotr.common.entity.npc.LOTRUnitTradeEntry;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
@Mixin(LOTRUnitTradeEntry.class)
|
|
||||||
public class MixinLOTRUnitTradeEntry implements ILOTRUnitTradeEntry {
|
|
||||||
@Shadow private LOTRUnitTradeEntry.PledgeType pledgeType;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LOTRUnitTradeEntry setObjective(String objective) {
|
|
||||||
Configuration config = new Configuration(new File("CinderLoE.cfg"));
|
|
||||||
boolean isObjectiveComplete = config.getBoolean(objective, Configuration.CATEGORY_GENERAL, false, "Set true if " + objective + " is complete");
|
|
||||||
|
|
||||||
if (!isObjectiveComplete) {
|
|
||||||
this.pledgeType = LOTRUnitTradeEntry.PledgeType.NONE;
|
|
||||||
}
|
|
||||||
return (LOTRUnitTradeEntry) (Object) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "hasRequiredCostAndAlignment", at = @At("HEAD"), cancellable = true, remap = false)
|
|
||||||
private void checkObjectiveBeforeHiring(EntityPlayer entityPlayer, LOTRHireableBase trader, CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
Configuration config = new Configuration(new File("CinderLoE.cfg"));
|
|
||||||
boolean isObjectiveComplete = config.getBoolean("objective_key", Configuration.CATEGORY_GENERAL, false, "Set true if the objective is complete");
|
|
||||||
|
|
||||||
if (!isObjectiveComplete) {
|
|
||||||
cir.setReturnValue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Loading…
Reference in New Issue