Rewrote directors so that they can work in the new system. Began adding content groups to the map server.

This commit is contained in:
Filip Maj
2017-01-29 11:07:28 -05:00
parent ad88c0b28a
commit f7482781e5
26 changed files with 638 additions and 359 deletions

View File

@@ -1,22 +1,53 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.actors.area;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
using System.IO;
namespace FFXIVClassic_Map_Server.actors.director
{
class Director : Actor
{
Player owner;
private uint directorId;
private string directorScriptPath;
private List<Actor> childrenOwners = new List<Actor>();
private bool isCreated = false;
public Director(Player owner, uint id) : base(id)
public Director(uint id, Area zone, string directorPath)
: base((6 << 28 | zone.actorId << 19 | (uint)id))
{
this.owner = owner;
directorId = id;
this.zone = zone;
directorScriptPath = directorPath;
DoActorInit(directorScriptPath);
GenerateActorName((int)id);
eventConditions = new EventList();
eventConditions.noticeEventConditions = new List<EventList.NoticeEventCondition>();
eventConditions.noticeEventConditions.Add(new EventList.NoticeEventCondition("noticeEvent", 0xE,0x0));
eventConditions.noticeEventConditions.Add(new EventList.NoticeEventCondition("noticeRequest",0x0,0x1));
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> actualLParams = new List<LuaParam>();
actualLParams.Insert(0, new LuaParam(2, classPath));
actualLParams.Insert(1, new LuaParam(4, 4));
actualLParams.Insert(2, new LuaParam(4, 4));
actualLParams.Insert(3, new LuaParam(4, 4));
actualLParams.Insert(4, new LuaParam(4, 4));
actualLParams.Insert(5, new LuaParam(4, 4));
actualLParams.Insert(6, new LuaParam(0, (int)0x13883));
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, actualLParams);
}
public virtual BasePacket GetSpawnPackets(uint playerActorId, uint spawnType)
public override BasePacket GetSpawnPackets(uint playerActorId, ushort spawnType)
{
List<SubPacket> subpackets = new List<SubPacket>();
subpackets.Add(CreateAddActorPacket(playerActorId, 0));
@@ -37,14 +68,127 @@ namespace FFXIVClassic_Map_Server.actors.director
return BasePacket.CreatePacket(initProperties.BuildPacket(playerActorId, actorId), true, false);
}
public void OnTalked(Npc npc)
public void OnTalked(Player player, Npc npc)
{
LuaEngine.DoDirectorOnTalked(this, owner, npc);
LuaEngine.DoDirectorOnTalked(this, player, npc);
}
public void OnCommand(Command command)
public void OnCommand(Player player, Command command)
{
LuaEngine.DoDirectorOnCommand(this, owner, command);
LuaEngine.DoDirectorOnCommand(this, player, command);
}
public void AddChild(Actor actor)
{
if (!childrenOwners.Contains(actor))
childrenOwners.Add(actor);
}
public void RemoveChild(Actor actor)
{
if (childrenOwners.Contains(actor))
childrenOwners.Remove(actor);
if (childrenOwners.Count == 0)
Server.GetWorldManager().GetZone(zoneId).DeleteDirector(actorId);
}
public void RemoveChildren()
{
childrenOwners.Clear();
Server.GetWorldManager().GetZone(zoneId).DeleteDirector(actorId);
}
public void DoActorInit(string directorPath)
{
LuaScript script = null;
if (File.Exists("./scripts/directors/" + directorPath + ".lua"))
script = LuaEngine.LoadScript("./scripts/directors/" + directorPath + ".lua");
else
return;
DynValue result;
if (script != null && script.Globals["init"] != null)
result = script.Call(script.Globals["init"], this);
else
return;
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
if (lparams.Count == 1 && lparams[0].value is string)
{
classPath = (string)lparams[0].value;
className = classPath.Substring(classPath.LastIndexOf("/") + 1);
isCreated = true;
}
}
public Coroutine GetEventStartCoroutine(Player player)
{
LuaScript script = null;
if (File.Exists("./scripts/directors/" + directorScriptPath + ".lua"))
script = LuaEngine.LoadScript("./scripts/directors/" + directorScriptPath + ".lua");
else
return null;
//Run Script
Coroutine coroutine;
if (script != null && !script.Globals.Get("onEventStarted").IsNil())
coroutine = script.CreateCoroutine(script.Globals["onEventStarted"]).Coroutine;
else
return null;
return coroutine;
}
public bool IsCreated()
{
return isCreated;
}
public void GenerateActorName(int actorNumber)
{
//Format Class Name
string className = this.className;
className = Char.ToLowerInvariant(className[0]) + className.Substring(1);
//Format Zone Name
string zoneName = zone.zoneName.Replace("Field", "Fld")
.Replace("Dungeon", "Dgn")
.Replace("Town", "Twn")
.Replace("Battle", "Btl")
.Replace("Test", "Tes")
.Replace("Event", "Evt")
.Replace("Ship", "Shp")
.Replace("Office", "Ofc");
if (zone is PrivateArea)
{
//Check if "normal"
zoneName = zoneName.Remove(zoneName.Length - 1, 1) + "P";
}
zoneName = Char.ToLowerInvariant(zoneName[0]) + zoneName.Substring(1);
try
{
className = className.Substring(0, 20 - zoneName.Length);
}
catch (ArgumentOutOfRangeException e)
{ }
//Convert actor number to base 63
string classNumber = Utils.ToStringBase63(actorNumber);
//Get stuff after @
uint zoneId = zone.actorId;
uint privLevel = 0;
if (zone is PrivateArea)
privLevel = ((PrivateArea)zone).GetPrivateAreaLevel();
actorName = String.Format("{0}_{1}_{2}@{3:X3}{4:X2}", className, zoneName, classNumber, zoneId, privLevel);
}
}

View File

@@ -1,41 +0,0 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using System;
using System.Collections.Generic;
namespace FFXIVClassic_Map_Server.actors.director
{
class OpeningDirector : Director
{
public OpeningDirector(Player player, uint id) : base(player, id)
{
this.displayNameId = 0;
this.customDisplayName = String.Format("openingDire_{0}_{1}", player.zone.zoneName, "04");
this.actorName = String.Format("openingDire_{0}_{1}@{2:x3}{3:x2}", player.zone.zoneName, "04", player.zoneId, 0);
this.actorName = this.actorName.Replace("Battle", "Btl");
this.className = "OpeningDirector";
this.eventConditions = new EventList();
List<EventList.NoticeEventCondition> noticeEventList = new List<EventList.NoticeEventCondition>();
noticeEventList.Add(new EventList.NoticeEventCondition("noticeEvent", 0xE, 0x0));
noticeEventList.Add(new EventList.NoticeEventCondition("noticeRequest", 0x0, 0x1));
this.eventConditions.noticeEventConditions = noticeEventList;
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList("/Director/OpeningDirector", false, false, false, false, 0x13881);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, lParams);
}
}
}

View File

@@ -1,49 +0,0 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.actors.director;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using System;
using System.Collections.Generic;
namespace FFXIVClassic_Map_Server.Actors
{
class WeatherDirector : Director
{
private uint weatherId;
public WeatherDirector(Player player, uint weatherId)
: base(player, 0x5FF80003)
{
this.weatherId = weatherId;
this.displayNameId = 0;
this.customDisplayName = String.Format("weatherDire_{0}_{1}", player.zone.zoneName, "07");
this.actorName = String.Format("weatherDire_{0}_{1}@{2:x3}{3:x2}", player.zone.zoneName, "04", player.zoneId, 0);
this.className = "Debug";
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList("/Director/Weather/WeatherDirector", false, false, false, false, weatherId);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, lParams);
}
public override BasePacket GetSpawnPackets(uint playerActorId)
{
List<SubPacket> subpackets = new List<SubPacket>();
subpackets.Add(CreateAddActorPacket(playerActorId, 0));
subpackets.Add(CreateSpeedPacket(playerActorId));
subpackets.Add(CreateSpawnPositonPacket(playerActorId, 0x1));
subpackets.Add(CreateNamePacket(playerActorId));
subpackets.Add(CreateStatePacket(playerActorId));
subpackets.Add(CreateIsZoneingPacket(playerActorId));
subpackets.Add(CreateScriptBindPacket(playerActorId));
return BasePacket.CreatePacket(subpackets, true, false);
}
}
}

View File

@@ -1,38 +0,0 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using System.Collections.Generic;
namespace FFXIVClassic_Map_Server.actors.director
{
class QuestDirectorMan0g001 : Director
{
public QuestDirectorMan0g001(Player player, uint id)
: base(player, id)
{
this.displayNameId = 0;
this.customDisplayName = "questDirect_fst0Btl03_01";
this.actorName = "questDirect_fst0Btl03_01@0A615";
this.className = "QuestDirectorMan0g001";
this.eventConditions = new EventList();
List<EventList.NoticeEventCondition> noticeEventList = new List<EventList.NoticeEventCondition>();
noticeEventList.Add(new EventList.NoticeEventCondition("noticeEvent", 0xE, 0x0));
noticeEventList.Add(new EventList.NoticeEventCondition("noticeRequest", 0x0, 0x1));
this.eventConditions.noticeEventConditions = noticeEventList;
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList("/Director/Quest/QuestDirectorMan0g001", false, false, false, false, false, 0x753A);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, lParams);
}
}
}

View File

@@ -1,38 +0,0 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using System.Collections.Generic;
namespace FFXIVClassic_Map_Server.actors.director
{
class QuestDirectorMan0l001 : Director
{
public QuestDirectorMan0l001(Player player, uint id)
: base(player, id)
{
this.displayNameId = 0;
this.customDisplayName = "questDirect_ocn0Btl02_01";
this.actorName = "questDirect_ocn0Btl02_01@0C196";
this.className = "QuestDirectorMan0l001";
this.eventConditions = new EventList();
List<EventList.NoticeEventCondition> noticeEventList = new List<EventList.NoticeEventCondition>();
noticeEventList.Add(new EventList.NoticeEventCondition("noticeEvent", 0xE, 0x0));
noticeEventList.Add(new EventList.NoticeEventCondition("noticeRequest", 0x0, 0x1));
this.eventConditions.noticeEventConditions = noticeEventList;
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList("/Director/Quest/QuestDirectorMan0l001", false, false, false, false, false, 0x7532);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, lParams);
}
}
}

View File

@@ -1,38 +0,0 @@

using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using System.Collections.Generic;
namespace FFXIVClassic_Map_Server.actors.director
{
class QuestDirectorMan0u001 : Director
{
public QuestDirectorMan0u001(Player player, uint id)
: base(player, id)
{
this.displayNameId = 0;
this.customDisplayName = "questDirect_wil0Btl01_01";
this.actorName = "questDirect_wil0Btl01_01@0A615";
this.className = "QuestDirectorMan0u001";
this.eventConditions = new EventList();
List<EventList.NoticeEventCondition> noticeEventList = new List<EventList.NoticeEventCondition>();
noticeEventList.Add(new EventList.NoticeEventCondition("noticeEvent", 0xE, 0x0));
noticeEventList.Add(new EventList.NoticeEventCondition("noticeRequest", 0x0, 0x1));
this.eventConditions.noticeEventConditions = noticeEventList;
}
public override SubPacket CreateScriptBindPacket(uint playerActorId)
{
List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList("/Director/Quest/QuestDirectorMan0u001", false, false, false, false, false, 0x757F);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, className, lParams);
}
}
}