mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 21:05:06 +00:00
Added quest start, complete, and turnin events, and a faction points event to scripted player events.
This commit is contained in:
1 parent
8919a182c5
commit
b024f800ae
9 files changed
+152
-20
No files matched your search
@@ -10,6 +10,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -19,6 +20,7 @@ import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.controllers.CustomGuiController;
|
||||
import noppes.npcs.controllers.Quest;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
@@ -335,4 +337,30 @@ public class EventHooks {
|
||||
noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent event = new noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent(player, gui);
|
||||
CustomGuiController.onClose(event);
|
||||
}
|
||||
|
||||
public static void onQuestFinished(EntityPlayer player, Quest quest){
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
QuestEvent.QuestCompletedEvent event = new QuestEvent.QuestCompletedEvent(new ScriptPlayer((EntityPlayerMP) player), quest);
|
||||
handler.callScript(EnumScriptType.QUEST_COMPLETED, event);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onQuestStarted(EntityPlayer player, Quest quest){
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
QuestEvent.QuestStartEvent event = new QuestEvent.QuestStartEvent(new ScriptPlayer((EntityPlayerMP) player), quest);
|
||||
handler.callScript(EnumScriptType.QUEST_START, event);
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onQuestTurnedIn(QuestEvent.QuestTurnedInEvent event){
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
handler.callScript(EnumScriptType.QUEST_TURNIN, event);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onFactionPoints(FactionEvent.FactionPoints event){
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
handler.callScript(EnumScriptType.FACTION_POINTS, event);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,10 @@ import noppes.npcs.controllers.TransportLocation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.event.QuestEvent;
|
||||
import noppes.npcs.scripted.interfaces.IItemStack;
|
||||
|
||||
public class NoppesUtilPlayer {
|
||||
|
||||
@@ -294,41 +298,58 @@ public class NoppesUtilPlayer {
|
||||
public static void questCompletion(EntityPlayerMP player, int questId) {
|
||||
PlayerQuestData playerdata = PlayerDataController.instance.getPlayerData(player).questData;
|
||||
QuestData data = playerdata.activeQuests.get(questId);
|
||||
|
||||
if(data == null)
|
||||
return;
|
||||
|
||||
|
||||
if(!data.quest.questInterface.isCompleted(player))
|
||||
return;
|
||||
|
||||
|
||||
QuestEvent.QuestTurnedInEvent event = new QuestEvent.QuestTurnedInEvent(new ScriptPlayer(player), data.quest);
|
||||
event.expReward = data.quest.rewardExp;
|
||||
|
||||
List<IItemStack> list = new ArrayList();
|
||||
Iterator var8 = data.quest.rewardItems.items.values().iterator();
|
||||
|
||||
while(var8.hasNext()) {
|
||||
ItemStack item = (ItemStack)var8.next();
|
||||
if (item.stackSize > 0) {
|
||||
list.add(NpcAPI.Instance().getIItemStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.quest.randomReward) {
|
||||
event.itemRewards = (IItemStack[])list.toArray(new IItemStack[list.size()]);
|
||||
} else if (!list.isEmpty()) {
|
||||
event.itemRewards = new IItemStack[]{(IItemStack)list.get(player.getRNG().nextInt(list.size()))};
|
||||
}
|
||||
|
||||
EventHooks.onQuestTurnedIn(event);
|
||||
IItemStack[] var12 = event.itemRewards;
|
||||
int var14 = var12.length;
|
||||
|
||||
for(int var10 = 0; var10 < var14; ++var10) {
|
||||
IItemStack item = var12[var10];
|
||||
if (item != null) {
|
||||
NoppesUtilServer.GivePlayerItem(player, player, item.getMCItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
data.quest.questInterface.handleComplete(player);
|
||||
if(data.quest.rewardExp > 0){
|
||||
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 0.5F * ((player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.7F + 1.8F));
|
||||
|
||||
player.addExperience(data.quest.rewardExp);
|
||||
|
||||
player.addExperience(data.quest.rewardExp);
|
||||
}
|
||||
data.quest.factionOptions.addPoints(player);
|
||||
if(data.quest.mail.isValid()){
|
||||
PlayerDataController.instance.addPlayerMessage(player.getCommandSenderName(), data.quest.mail);
|
||||
}
|
||||
if(!data.quest.randomReward){
|
||||
for(ItemStack item : data.quest.rewardItems.items.values()){
|
||||
NoppesUtilServer.GivePlayerItem(player, player, item);
|
||||
}
|
||||
}
|
||||
else{
|
||||
List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
for(ItemStack item : data.quest.rewardItems.items.values()){
|
||||
if(item != null && item.getItem() != null)
|
||||
list.add(item);
|
||||
}
|
||||
if(!list.isEmpty()){
|
||||
NoppesUtilServer.GivePlayerItem(player, player, list.get(player.getRNG().nextInt(list.size())));
|
||||
}
|
||||
}
|
||||
|
||||
if(!data.quest.command.isEmpty()){
|
||||
NoppesUtilServer.runCommand(player, "QuestCompletion", data.quest.command);
|
||||
}
|
||||
|
||||
PlayerQuestController.setQuestFinished(data.quest, player);
|
||||
if(data.quest.hasNewQuest()) PlayerQuestController.addActiveQuest(data.quest.getNextQuest(), player);
|
||||
}
|
||||
|
||||
@@ -135,6 +135,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookList.add("playSound");
|
||||
hookList.add("lightning");
|
||||
hookList.add("changedDim");
|
||||
hookList.add("questStart");
|
||||
hookList.add("questCompleted");
|
||||
hookList.add("questTurnIn");
|
||||
hookList.add("factionPoints");
|
||||
hookList.add("customGuiClosed");
|
||||
hookList.add("customGuiButton");
|
||||
hookList.add("customGuiSlot");
|
||||
|
||||
@@ -47,6 +47,7 @@ public enum EnumScriptType {
|
||||
QUEST_START("questStart"),
|
||||
QUEST_COMPLETED("questCompleted"),
|
||||
QUEST_TURNIN("questTurnIn"),
|
||||
FACTION_POINTS("factionPoints"),
|
||||
KEY_PRESSED("keyPressed"),
|
||||
CUSTOM_CHEST_CLOSED("customChestClosed"),
|
||||
CUSTOM_CHEST_CLICKED("customChestClicked"),
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.event.FactionEvent;
|
||||
|
||||
public class FactionOptions {
|
||||
|
||||
@@ -55,7 +59,9 @@ public class FactionOptions {
|
||||
Faction faction = FactionController.getInstance().get(factionId);
|
||||
if(faction == null)
|
||||
return;
|
||||
|
||||
|
||||
EventHooks.onFactionPoints(new FactionEvent.FactionPoints(new ScriptPlayer((EntityPlayerMP) player), faction, decrease, points));
|
||||
|
||||
if(!faction.hideFaction){
|
||||
String message = decrease?"faction.decreasepoints":"faction.increasepoints";
|
||||
player.addChatMessage(new ChatComponentTranslation(message, faction.name, points));
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Vector;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
@@ -30,6 +31,10 @@ public class PlayerQuestController {
|
||||
public static void addActiveQuest(Quest quest, EntityPlayer player) {
|
||||
PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData;
|
||||
if(canQuestBeAccepted(quest, player)){
|
||||
if (EventHooks.onQuestStarted(player, quest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.activeQuests.put(quest.id,new QuestData(quest));
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
@@ -103,6 +104,7 @@ public class PlayerQuestData {
|
||||
}
|
||||
data.isCompleted = true;
|
||||
bo = true;
|
||||
EventHooks.onQuestFinished(player,data.quest);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import noppes.npcs.scripted.handler.data.IFaction;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
|
||||
public class FactionEvent extends CustomNPCsEvent {
|
||||
public final IFaction faction;
|
||||
public final IPlayer player;
|
||||
|
||||
public FactionEvent(IPlayer player, IFaction faction){
|
||||
this.faction = faction;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static class FactionPoints extends FactionEvent {
|
||||
public boolean decrease;
|
||||
public int points;
|
||||
|
||||
public FactionPoints(IPlayer player, IFaction faction, boolean decrease, int points) {
|
||||
super(player, faction);
|
||||
this.decrease = decrease;
|
||||
this.points = points;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import noppes.npcs.scripted.handler.data.IQuest;
|
||||
import noppes.npcs.scripted.interfaces.IItemStack;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
|
||||
public class QuestEvent extends CustomNPCsEvent {
|
||||
public final IQuest quest;
|
||||
public final IPlayer player;
|
||||
|
||||
public QuestEvent(IPlayer player, IQuest quest) {
|
||||
this.quest = quest;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static class QuestCompletedEvent extends QuestEvent {
|
||||
public QuestCompletedEvent(IPlayer player, IQuest quest) {
|
||||
super(player, quest);
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class QuestStartEvent extends QuestEvent {
|
||||
public QuestStartEvent(IPlayer player, IQuest quest) {
|
||||
super(player, quest);
|
||||
}
|
||||
}
|
||||
|
||||
public static class QuestTurnedInEvent extends QuestEvent {
|
||||
public int expReward;
|
||||
public IItemStack[] itemRewards = new IItemStack[0];
|
||||
|
||||
public QuestTurnedInEvent(IPlayer player, IQuest quest) {
|
||||
super(player, quest);
|
||||
this.expReward = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user