Updated Map Server namespace. Moved all other data folders (www and sql) to data folder. Renamed boot name to Project Meteor.

This commit is contained in:
Filip Maj 2019-06-19 01:10:15 -04:00
parent 18ef69f3d1
commit 91549bff7a
1823 changed files with 102704 additions and 901 deletions

View file

@ -0,0 +1,342 @@
/*
===========================================================================
Copyright (C) 2015-2019 Project Meteor Dev Team
This file is part of Project Meteor Server.
Project Meteor Server is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Project Meteor Server is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
===========================================================================
*/
using Meteor.Common;
using Meteor.Map.actors.area;
using Meteor.Map.actors.group;
using Meteor.Map.Actors;
using Meteor.Map.lua;
using Meteor.Map.packets.send.actor;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
namespace Meteor.Map.actors.director
{
class Director : Actor
{
private uint directorId;
private string directorScriptPath;
private List<Actor> members = new List<Actor>();
protected ContentGroup contentGroup;
private bool isCreated = false;
private bool isDeleted = false;
private bool isDeleting = false;
private Script directorScript;
private Coroutine currentCoroutine;
public Director(uint id, Area zone, string directorPath, bool hasContentGroup, params object[] args)
: base((6 << 28 | zone.actorId << 19 | (uint)id))
{
directorId = id;
this.zone = zone;
this.zoneId = zone.actorId;
directorScriptPath = directorPath;
LoadLuaScript();
if (hasContentGroup)
contentGroup = Server.GetWorldManager().CreateContentGroup(this, GetMembers());
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));
eventConditions.noticeEventConditions.Add(new EventList.NoticeEventCondition("reqForChild", 0x0, 0x1));
}
public override SubPacket CreateScriptBindPacket()
{
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));
List<LuaParam> lparams = LuaEngine.GetInstance().CallLuaFunctionForReturn(null, this, "init", false);
for (int i = 1; i < lparams.Count; i++)
actualLParams.Add(lparams[i]);
return ActorInstantiatePacket.BuildPacket(actorId, actorName, className, actualLParams);
}
public override List<SubPacket> GetSpawnPackets(ushort spawnType = 1)
{
List<SubPacket> subpackets = new List<SubPacket>();
subpackets.Add(CreateAddActorPacket(0));
subpackets.AddRange(GetEventConditionPackets());
subpackets.Add(CreateSpeedPacket());
subpackets.Add(CreateSpawnPositonPacket(0));
subpackets.Add(CreateNamePacket());
subpackets.Add(CreateStatePacket());
subpackets.Add(CreateIsZoneingPacket());
subpackets.Add(CreateScriptBindPacket());
return subpackets;
}
public override List<SubPacket> GetInitPackets()
{
List<SubPacket> subpackets = new List<SubPacket>();
SetActorPropetyPacket initProperties = new SetActorPropetyPacket("/_init");
initProperties.AddTarget();
subpackets.Add(initProperties.BuildPacket(actorId));
return subpackets;
}
public void OnTalkEvent(Player player, Npc npc)
{
LuaEngine.GetInstance().CallLuaFunction(player, this, "onTalkEvent", false, npc);
}
public void OnCommandEvent(Player player, Command command)
{
LuaEngine.GetInstance().CallLuaFunction(player, this, "onCommandEvent", false, command);
}
public void StartDirector(bool spawnImmediate, params object[] args)
{
object[] args2 = new object[args.Length + 1];
args2[0] = this;
Array.Copy(args, 0, args2, 1, args.Length);
List<LuaParam> lparams = CallLuaScript("init", args2);
if (lparams != null && lparams.Count >= 1 && lparams[0].value is string)
{
classPath = (string)lparams[0].value;
className = classPath.Substring(classPath.LastIndexOf("/") + 1);
GenerateActorName((int)directorId);
isCreated = true;
}
if (isCreated && spawnImmediate)
{
if (contentGroup != null)
contentGroup.Start();
foreach (Player p in GetPlayerMembers())
{
p.QueuePackets(GetSpawnPackets());
p.QueuePackets(GetInitPackets());
}
}
if (this is GuildleveDirector)
{
((GuildleveDirector)this).LoadGuildleve();
}
CallLuaScript("main", this, contentGroup);
}
public void StartContentGroup()
{
if (contentGroup != null)
contentGroup.Start();
}
public void EndDirector()
{
isDeleting = true;
if (contentGroup != null)
contentGroup.DeleteGroup();
if (this is GuildleveDirector)
((GuildleveDirector)this).EndGuildleveDirector();
List<Actor> players = GetPlayerMembers();
foreach (Actor player in players)
((Player)player).RemoveDirector(this);
members.Clear();
isDeleted = true;
Server.GetWorldManager().GetZone(zoneId).DeleteDirector(actorId);
}
public void AddMember(Actor actor)
{
if (!members.Contains(actor))
{
members.Add(actor);
if (actor is Player)
((Player)actor).AddDirector(this);
if (contentGroup != null)
contentGroup.AddMember(actor);
}
}
public void RemoveMember(Actor actor)
{
if (members.Contains(actor))
members.Remove(actor);
if (contentGroup != null)
contentGroup.RemoveMember(actor.actorId);
if (GetPlayerMembers().Count == 0 && !isDeleting)
EndDirector();
}
public List<Actor> GetMembers()
{
return members;
}
public List<Actor> GetPlayerMembers()
{
return members.FindAll(s => s is Player);
}
public List<Actor> GetNpcMembers()
{
return members.FindAll(s => s is Npc);
}
public bool IsCreated()
{
return isCreated;
}
public bool IsDeleted()
{
return isDeleted;
}
public bool HasContentGroup()
{
return contentGroup != null;
}
public ContentGroup GetContentGroup()
{
return contentGroup;
}
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)
{ }
//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).GetPrivateAreaType();
actorName = String.Format("{0}_{1}_{2}@{3:X3}{4:X2}", className, zoneName, classNumber, zoneId, privLevel);
}
public string GetScriptPath()
{
return directorScriptPath;
}
private void LoadLuaScript()
{
string luaPath = String.Format(LuaEngine.FILEPATH_DIRECTORS, GetScriptPath());
directorScript = LuaEngine.LoadScript(luaPath);
if (directorScript == null)
Program.Log.Error("Could not find script for director {0}.", GetName());
}
private List<LuaParam> CallLuaScript(string funcName, params object[] args)
{
if (directorScript != null)
{
directorScript = LuaEngine.LoadScript(String.Format(LuaEngine.FILEPATH_DIRECTORS, directorScriptPath));
if (!directorScript.Globals.Get(funcName).IsNil())
{
DynValue result = directorScript.Call(directorScript.Globals[funcName], args);
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
return lparams;
}
else
Program.Log.Error("Could not find script for director {0}.", GetName());
}
return null;
}
private List<LuaParam> StartCoroutine(string funcName, params object[] args)
{
if (directorScript != null)
{
if (!directorScript.Globals.Get(funcName).IsNil())
{
currentCoroutine = directorScript.CreateCoroutine(directorScript.Globals[funcName]).Coroutine;
DynValue value = currentCoroutine.Resume(args);
LuaEngine.GetInstance().ResolveResume(null, currentCoroutine, value);
}
else
Program.Log.Error("Could not find script for director {0}.", GetName());
}
return null;
}
public void OnEventStart(Player player, object[] args)
{
object[] args2 = new object[args.Length + (player == null ? 1 : 2)];
Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length);
if (player != null)
{
args2[0] = player;
args2[1] = this;
}
else
args2[0] = this;
Coroutine coroutine = directorScript.CreateCoroutine(directorScript.Globals["onEventStarted"]).Coroutine;
DynValue value = coroutine.Resume(args2);
LuaEngine.GetInstance().ResolveResume(player, coroutine, value);
}
}
}

View file

@ -0,0 +1,272 @@
/*
===========================================================================
Copyright (C) 2015-2019 Project Meteor Dev Team
This file is part of Project Meteor Server.
Project Meteor Server is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Project Meteor Server is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
===========================================================================
*/
using Meteor.Common;
using Meteor.Map.actors.director.Work;
using Meteor.Map.Actors;
using Meteor.Map.dataobjects;
using Meteor.Map.utils;
using System;
using System.Collections.Generic;
namespace Meteor.Map.actors.director
{
class GuildleveDirector : Director
{
public uint guildleveId;
public Player guildleveOwner;
public byte selectedDifficulty;
public GuildleveData guildleveData;
public GuildleveWork guildleveWork = new GuildleveWork();
public bool isEnded = false;
public uint completionTime = 0;
public GuildleveDirector(uint id, Area zone, string directorPath, uint guildleveId, byte selectedDifficulty, Player guildleveOwner, params object[] args)
: base(id, zone, directorPath, true, args)
{
this.guildleveId = guildleveId;
this.selectedDifficulty = selectedDifficulty;
this.guildleveData = Server.GetGuildleveGamedata(guildleveId);
this.guildleveOwner = guildleveOwner;
guildleveWork.aimNum[0] = guildleveData.aimNum[0];
guildleveWork.aimNum[1] = guildleveData.aimNum[1];
guildleveWork.aimNum[2] = guildleveData.aimNum[2];
guildleveWork.aimNum[3] = guildleveData.aimNum[3];
if (guildleveWork.aimNum[0] != 0)
guildleveWork.uiState[0] = 1;
if (guildleveWork.aimNum[1] != 0)
guildleveWork.uiState[1] = 1;
if (guildleveWork.aimNum[2] != 0)
guildleveWork.uiState[2] = 1;
if (guildleveWork.aimNum[3] != 0)
guildleveWork.uiState[3] = 1;
guildleveWork.aimNumNow[0] = guildleveWork.aimNumNow[1] = guildleveWork.aimNumNow[2] = guildleveWork.aimNumNow[3] = 0;
}
public void LoadGuildleve()
{
}
public void StartGuildleve()
{
foreach (Actor p in GetPlayerMembers())
{
Player player = (Player) p;
//Set music
if (guildleveData.location == 1)
player.ChangeMusic(22);
else if (guildleveData.location == 2)
player.ChangeMusic(14);
else if (guildleveData.location == 3)
player.ChangeMusic(26);
else if (guildleveData.location == 4)
player.ChangeMusic(16);
//Show Start Messages
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50022, 0x20, guildleveId, selectedDifficulty);
player.SendDataPacket("attention", Server.GetWorldManager().GetActor(), "", 50022, guildleveId, selectedDifficulty);
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50026, 0x20, (object)(int)guildleveData.timeLimit);
}
guildleveWork.startTime = Utils.UnixTimeStampUTC();
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/start", this);
propertyBuilder.AddProperty("guildleveWork.startTime");
SendPacketsToPlayers(propertyBuilder.Done());
}
public void EndGuildleve(bool wasCompleted)
{
if (isEnded)
return;
isEnded = true;
completionTime = Utils.UnixTimeStampUTC() - guildleveWork.startTime;
if (wasCompleted)
{
foreach (Actor a in GetPlayerMembers())
{
Player player = (Player)a;
player.MarkGuildleve(guildleveId, true, true);
player.PlayAnimation(0x02000002, true);
player.ChangeMusic(81);
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50023, 0x20, (object)(int)guildleveId);
player.SendDataPacket("attention", Server.GetWorldManager().GetActor(), "", 50023, (object)(int)guildleveId);
}
}
foreach (Actor a in GetNpcMembers())
{
Npc npc = (Npc)a;
npc.Despawn();
RemoveMember(a);
}
guildleveWork.startTime = 0;
guildleveWork.signal = -1;
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/signal", this);
propertyBuilder.AddProperty("guildleveWork.signal");
propertyBuilder.NewTarget("guildleveWork/start");
propertyBuilder.AddProperty("guildleveWork.startTime");
SendPacketsToPlayers(propertyBuilder.Done());
if (wasCompleted)
{
Npc aetheryteNode = zone.SpawnActor(1200040, String.Format("{0}:warpExit", guildleveOwner.actorName), guildleveOwner.positionX, guildleveOwner.positionY, guildleveOwner.positionZ);
AddMember(aetheryteNode);
foreach (Actor a in GetPlayerMembers())
{
Player player = (Player)a;
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50029, 0x20);
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50032, 0x20);
}
}
}
public void AbandonGuildleve()
{
foreach (Actor p in GetPlayerMembers())
{
Player player = (Player)p;
player.SendGameMessage(Server.GetWorldManager().GetActor(), 50147, 0x20, (object)guildleveId);
player.MarkGuildleve(guildleveId, true, false);
}
EndGuildleve(false);
EndDirector();
}
//Delete ContentGroup, change music back
public void EndGuildleveDirector()
{
foreach (Actor p in GetPlayerMembers())
{
Player player = (Player)p;
player.ChangeMusic(player.GetZone().bgmDay);
}
}
public void SyncAllInfo()
{
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/infoVariable", this);
if (guildleveWork.aimNum[0] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNum[0]");
if (guildleveWork.aimNum[1] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNum[1]");
if (guildleveWork.aimNum[2] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNum[2]");
if (guildleveWork.aimNum[3] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNum[3]");
if (guildleveWork.aimNumNow[0] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNumNow[0]");
if (guildleveWork.aimNumNow[1] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNumNow[1]");
if (guildleveWork.aimNumNow[2] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNumNow[2]");
if (guildleveWork.aimNumNow[3] != 0)
propertyBuilder.AddProperty("guildleveWork.aimNumNow[3]");
if (guildleveWork.uiState[0] != 0)
propertyBuilder.AddProperty("guildleveWork.uiState[0]");
if (guildleveWork.uiState[1] != 0)
propertyBuilder.AddProperty("guildleveWork.uiState[1]");
if (guildleveWork.uiState[2] != 0)
propertyBuilder.AddProperty("guildleveWork.uiState[2]");
if (guildleveWork.uiState[3] != 0)
propertyBuilder.AddProperty("guildleveWork.uiState[3]");
SendPacketsToPlayers(propertyBuilder.Done());
}
public void UpdateAimNumNow(int index, sbyte value)
{
guildleveWork.aimNumNow[index] = value;
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/infoVariable", this);
propertyBuilder.AddProperty(String.Format("guildleveWork.aimNumNow[{0}]", index));
SendPacketsToPlayers(propertyBuilder.Done());
}
public void UpdateUiState(int index, sbyte value)
{
guildleveWork.uiState[index] = value;
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/infoVariable", this);
propertyBuilder.AddProperty(String.Format("guildleveWork.uiState[{0}]", index));
SendPacketsToPlayers(propertyBuilder.Done());
}
public void UpdateMarkers(int markerIndex, float x, float y, float z)
{
guildleveWork.markerX[markerIndex] = x;
guildleveWork.markerY[markerIndex] = y;
guildleveWork.markerZ[markerIndex] = z;
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("guildleveWork/marker", this);
propertyBuilder.AddProperty(String.Format("guildleveWork.markerX[{0}]", markerIndex));
propertyBuilder.AddProperty(String.Format("guildleveWork.markerY[{0}]", markerIndex));
propertyBuilder.AddProperty(String.Format("guildleveWork.markerZ[{0}]", markerIndex));
SendPacketsToPlayers(propertyBuilder.Done());
}
public void SendPacketsToPlayers(List<SubPacket> packets)
{
List<Actor> players = GetPlayerMembers();
foreach (Actor p in players)
{
((Player)p).QueuePackets(packets);
}
}
public static uint GlBorderIconIDToAnimID(uint iconId)
{
return iconId - 20000;
}
public static uint GlPlateIconIDToAnimID(uint iconId)
{
return iconId - 20020;
}
public static uint GetGLStartAnimationFromSheet(uint border, uint plate, bool isBoost)
{
return GetGLStartAnimation(GlBorderIconIDToAnimID(border), GlPlateIconIDToAnimID(plate), isBoost);
}
public static uint GetGLStartAnimation(uint border, uint plate, bool isBoost)
{
uint borderBits = border;
uint plateBits = plate << 7;
uint boostBits = isBoost ? (uint)0x8000 : (uint) 0;
return 0x0B000000 | boostBits | plateBits | borderBits;
}
}
}

View file

@ -0,0 +1,37 @@
/*
===========================================================================
Copyright (C) 2015-2019 Project Meteor Dev Team
This file is part of Project Meteor Server.
Project Meteor Server is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Project Meteor Server is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
===========================================================================
*/
namespace Meteor.Map.actors.director.Work
{
class GuildleveWork
{
public uint startTime = 0;
public sbyte[] aimNum = new sbyte[4];
public sbyte[] aimNumNow = new sbyte[4];
public sbyte[] uiState = new sbyte[4];
public float[] markerX = new float[3];
public float[] markerY = new float[3];
public float[] markerZ = new float[3];
public sbyte signal;
}
}