mirror of
				https://bitbucket.org/Ioncannon/project-meteor-server.git
				synced 2025-05-20 08:26:59 -04:00 
			
		
		
		
	Modified scripts to work with new system.
This commit is contained in:
		| @@ -38,6 +38,7 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|  | ||||
|         public bool spawnedFirstTime = false; | ||||
|  | ||||
|         public string classPath; | ||||
|         public string className; | ||||
|         public List<LuaParam> classParams; | ||||
|  | ||||
|   | ||||
| @@ -5,12 +5,15 @@ using FFXIVClassic_Map_Server.actors; | ||||
| using FFXIVClassic_Map_Server.Actors.Chara; | ||||
| using FFXIVClassic_Map_Server.dataobjects; | ||||
| using FFXIVClassic_Map_Server.lua; | ||||
| using FFXIVClassic_Map_Server.packets.receive.events; | ||||
| using FFXIVClassic_Map_Server.packets.send.actor; | ||||
| using FFXIVClassic_Map_Server.utils; | ||||
| using MoonSharp.Interpreter; | ||||
| using MySql.Data.MySqlClient; | ||||
| using Newtonsoft.Json; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| @@ -19,6 +22,7 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
| { | ||||
|     class Npc : Character | ||||
|     { | ||||
|         private Script actorScript; | ||||
|         private uint actorClassId; | ||||
|  | ||||
|         public NpcWork npcWork = new NpcWork(); | ||||
| @@ -31,7 +35,6 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|             this.positionZ = posZ; | ||||
|             this.rotation = rot; | ||||
|             this.animationId = animationId; | ||||
|             this.className = className; | ||||
|  | ||||
|             this.displayNameId = displayNameId; | ||||
|             this.customDisplayName = customDisplayName; | ||||
| @@ -41,6 +44,7 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|  | ||||
|             loadNpcAppearance(classId); | ||||
|  | ||||
|             this.classPath = classPath; | ||||
|             className = classPath.Substring(classPath.LastIndexOf("/")+1); | ||||
|  | ||||
|             charaWork.battleSave.potencial = 1.0f; | ||||
| @@ -63,7 +67,7 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|             charaWork.property[3] = 1; | ||||
|             charaWork.property[4] = 1; | ||||
|  | ||||
|             generateActorName((int)actorNumber); | ||||
|             generateActorName((int)actorNumber);             | ||||
|         } | ||||
|  | ||||
|         public SubPacket createAddActorPacket(uint playerActorId) | ||||
| @@ -73,17 +77,8 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|  | ||||
|         public override SubPacket createScriptBindPacket(uint playerActorId) | ||||
|         { | ||||
|             List<LuaParam> lParams; | ||||
|  | ||||
|             Player player = Server.GetWorldManager().GetPCInWorld(playerActorId); | ||||
|             lParams = LuaEngine.doActorInstantiate(player, this); | ||||
|  | ||||
|             if (lParams == null) | ||||
|             { | ||||
|                 className = "PopulaceStandard"; | ||||
|                 lParams = LuaUtils.createLuaParamList("/Chara/Npc/Populace/PopulaceStandard", false, false, false, false, false, 0xF47F6, false, false, 0, 1, "TEST"); | ||||
|             } | ||||
|  | ||||
|             List<LuaParam> lParams = LuaUtils.createLuaParamList(classPath, false, false, false, false, false, actorClassId, false, false, 0, 1, "TEST"); | ||||
|              | ||||
|             return ActorInstantiatePacket.buildPacket(actorId, playerActorId, actorName, className, lParams); | ||||
|         } | ||||
|  | ||||
| @@ -258,5 +253,70 @@ namespace FFXIVClassic_Map_Server.Actors | ||||
|             EventList conditions = JsonConvert.DeserializeObject<EventList>(eventConditions); | ||||
|             this.eventConditions = conditions; | ||||
|         } | ||||
|  | ||||
|         public void DoEventStart(Player player, EventStartPacket eventStart) | ||||
|         { | ||||
|             if (File.Exists("./scripts" + classPath + ".lua")) | ||||
|                 actorScript = LuaEngine.loadScript("./scripts" + classPath + ".lua"); | ||||
|  | ||||
|             if (actorScript == null) | ||||
|             {  | ||||
|                 LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", getName())); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             //Have to do this to combine LuaParams | ||||
|             List<Object> objects = new List<Object>(); | ||||
|             objects.Add(player); | ||||
|             objects.Add(this); | ||||
|             objects.Add(eventStart.triggerName); | ||||
|  | ||||
|             if (eventStart.luaParams != null) | ||||
|                 objects.AddRange(LuaUtils.createLuaParamObjectList(eventStart.luaParams)); | ||||
|  | ||||
|             //Run Script | ||||
|             if (!actorScript.Globals.Get("onEventStarted").IsNil()) | ||||
|                 actorScript.Call(actorScript.Globals["onEventStarted"], objects.ToArray()); | ||||
|          | ||||
|         } | ||||
|  | ||||
|         public void DoEventUpdate(Player player, EventUpdatePacket eventUpdate) | ||||
|         { | ||||
|             if (File.Exists("./scripts" + classPath + ".lua")) | ||||
|                 actorScript = LuaEngine.loadScript("./scripts" + classPath + ".lua"); | ||||
|  | ||||
|             if (actorScript == null) | ||||
|             { | ||||
|                 LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", getName())); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             //Have to do this to combine LuaParams | ||||
|             List<Object> objects = new List<Object>(); | ||||
|             objects.Add(player); | ||||
|             objects.Add(this); | ||||
|             objects.Add(eventUpdate.val2); | ||||
|             objects.AddRange(LuaUtils.createLuaParamObjectList(eventUpdate.luaParams)); | ||||
|  | ||||
|             //Run Script | ||||
|             if (!actorScript.Globals.Get("onEventUpdate").IsNil()) | ||||
|                 actorScript.Call(actorScript.Globals["onEventUpdate"], objects.ToArray()); | ||||
|         } | ||||
|  | ||||
|         internal void DoOnActorSpawn(Player player) | ||||
|         { | ||||
|             if (File.Exists("./scripts" + classPath + ".lua")) | ||||
|                 actorScript = LuaEngine.loadScript("./scripts" + classPath + ".lua"); | ||||
|  | ||||
|             if (actorScript == null) | ||||
|             { | ||||
|                 LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", getName())); | ||||
|                 return; | ||||
|             } | ||||
|                 | ||||
|             //Run Script | ||||
|             if (!actorScript.Globals.Get("onSpawn").IsNil()) | ||||
|                 actorScript.Call(actorScript.Globals["onSpawn"], player, this);             | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -150,7 +150,7 @@ namespace FFXIVClassic_Map_Server.dataobjects | ||||
|  | ||||
|                     if (actor is Npc) | ||||
|                     { | ||||
|                         LuaEngine.doActorOnSpawn(getActor(), (Npc)actor); | ||||
|                         ((Npc)actor).DoOnActorSpawn(playerActor); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -62,6 +62,12 @@ namespace FFXIVClassic_Map_Server.lua | ||||
|  | ||||
|         public static void doActorOnEventStarted(Player player, Actor target, EventStartPacket eventStart) | ||||
|         { | ||||
|             if (target is Npc) | ||||
|             { | ||||
|                 ((Npc)target).DoEventStart(player, eventStart); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             string luaPath; | ||||
|  | ||||
|             if (target is Command) | ||||
| @@ -126,6 +132,12 @@ namespace FFXIVClassic_Map_Server.lua | ||||
|  | ||||
|         public static void doActorOnEventUpdated(Player player, Actor target, EventUpdatePacket eventUpdate) | ||||
|         { | ||||
|             if (target is Npc) | ||||
|             { | ||||
|                 ((Npc)target).DoEventUpdate(player, eventUpdate); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             string luaPath;  | ||||
|  | ||||
|             if (target is Command)             | ||||
| @@ -206,7 +218,7 @@ namespace FFXIVClassic_Map_Server.lua | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private static Script loadScript(string filename) | ||||
|         public static Script loadScript(string filename) | ||||
|         { | ||||
|             Script script = new Script(); | ||||
|             ((FileSystemScriptLoader)script.Options.ScriptLoader).ModulePaths = FileSystemScriptLoader.UnpackStringPaths("./scripts/?;./scripts/?.lua"); | ||||
| @@ -227,7 +239,7 @@ namespace FFXIVClassic_Map_Server.lua | ||||
|             return script; | ||||
|         } | ||||
|  | ||||
|         private static void SendError(Player player, string message) | ||||
|         public static void SendError(Player player, string message) | ||||
|         { | ||||
|             List<SubPacket> sendError = new List<SubPacket>(); | ||||
|             sendError.Add(EndEventPacket.buildPacket(player.actorId, player.currentEventOwner, player.currentEventName)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user