fixed some timers

- status icons now display (<3 u ion)
- todo: populate status tables, figure out why effect wont tick down for me
This commit is contained in:
Tahir Akhlaq 2017-07-27 03:58:42 +01:00
parent ddad27a5f9
commit 8bebba64b3
10 changed files with 55 additions and 35 deletions

View File

@ -1814,11 +1814,15 @@ namespace FFXIVClassic_Map_Server
{
var duration = effect.GetDurationMs() + effect.GetStartTime().Millisecond - Program.Tick.Millisecond;
queries += Environment.NewLine + $"REPLACE INTO characters_statuseffect(characterId, statusId, magnitude, duration, tick, tier, extra) VALUES ({player.actorId}, {effect.GetEffectId()}, {effect.GetMagnitude()}, {duration}, {effect.GetTickMs()}, {effect.GetTier()}, {effect.GetExtra()});";
queries += Environment.NewLine + $"REPLACE INTO characters_statuseffect(characterId, statusId, magnitude, duration, tick, tier, extra) VALUES ({player.actorId}, {effect.GetStatusEffectId()}, {effect.GetMagnitude()}, {duration}, {effect.GetTickMs()}, {effect.GetTier()}, {effect.GetExtra()});";
}
if (queries.Length > 0)
{
MySqlCommand cmd = new MySqlCommand(queries, conn);
cmd.ExecuteNonQuery();
}
}
catch (MySqlException e)
{
Program.Log.Error(e.ToString());

View File

@ -43,6 +43,7 @@ namespace FFXIVClassic_Map_Server.Actors
public List<Vector3> positionUpdates = new List<Vector3>();
public DateTime lastMoveUpdate;
protected DateTime lastUpdate;
public Actor target;
public bool hasMoved = false;
@ -161,7 +162,7 @@ namespace FFXIVClassic_Map_Server.Actors
updateMs = 150;
}
if (forceUpdate || (hasMoved && ((this is Player) || diffTime.Milliseconds >= updateMs)))
if (forceUpdate || (hasMoved && ((this is Player) || diffTime.TotalMilliseconds >= updateMs)))
{
hasMoved = (this.positionUpdates != null && this.positionUpdates.Count > 0);
if (hasMoved)

View File

@ -617,7 +617,7 @@ namespace FFXIVClassic_Map_Server.Actors
foreach (Actor a in mActorList.Values)
a.Update(tick);
var deltaTime = (tick - Program.LastTick).Milliseconds;
var deltaTime = (tick - Program.LastTick).TotalMilliseconds;
LuaEngine.GetInstance().CallLuaFunction(null, this, "onUpdate", true, deltaTime);
}
}

View File

@ -28,8 +28,6 @@ namespace FFXIVClassic_Map_Server.actors.area
public Int64 pathCalls;
public Int64 pathCallTime;
protected DateTime lastUpdate;
public Zone(uint id, string zoneName, ushort regionId, string classPath, ushort bgmDay, ushort bgmNight, ushort bgmBattle, bool isIsolated, bool isInn, bool canRideChocobo, bool canStealth, bool isInstanceRaid, bool loadNavMesh = false)
: base(id, zoneName, regionId, classPath, bgmDay, bgmNight, bgmBattle, isIsolated, isInn, canRideChocobo, canStealth, isInstanceRaid)
{
@ -170,16 +168,18 @@ namespace FFXIVClassic_Map_Server.actors.area
var diffTime = tick - lastUpdate;
// arbitrary cap
if (diffTime.Milliseconds >= 33)
if (diffTime.TotalMilliseconds >= 33)
{
}
if (diffTime.Seconds >= 10)
if (diffTime.TotalSeconds >= 10)
{
if (this.pathCalls > 0)
{
Program.Log.Error("Number of pathfinding calls {0} average time {1}", pathCalls, pathCallTime / pathCalls);
}
// todo: this is stupid debug stuff that needs to fuck off
lastUpdate = tick;
}
}

View File

@ -414,7 +414,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public bool Update(DateTime tick)
{
// todo: maybe not tick if already reached duration?
if (tickMs != 0 && (lastTick - startTime).Milliseconds >= tickMs)
if (tickMs != 0 && (lastTick - startTime).TotalMilliseconds >= tickMs)
{
// todo: call effect's onTick
// todo: maybe keep a global lua object instead of creating a new one each time we wanna call a script
@ -422,7 +422,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
LuaEngine.CallLuaStatusEffectFunction(this.owner, this, "onTick", this.owner, this);
}
// todo: handle infinite duration effects?
if (durationMs != 0 && startTime.Millisecond + durationMs >= tick.Millisecond)
if (durationMs != 0 && (tick - startTime).TotalMilliseconds >= durationMs)
{
// todo: call effect's onLose
// todo: broadcast effect lost packet
@ -436,12 +436,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return owner;
}
public uint GetEffectId()
public uint GetStatusEffectId()
{
return (uint)id;
}
public ushort GetEffectIdForCharaWork()
public ushort GetStatusId()
{
return (ushort)(id - 200000);
}

View File

@ -17,7 +17,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
private Character owner;
private readonly Dictionary<uint, StatusEffect> effects;
public static readonly int MAX_EFFECTS = 20;
private bool sendUpdate = false;
public StatusEffectContainer(Character owner)
{
this.owner = owner;
@ -40,19 +40,31 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
RemoveStatusEffect(effect);
}
if (sendUpdate)
{
}
sendUpdate = false;
}
public bool AddStatusEffect(uint id, UInt64 magnitude, double tickMs, double durationMs, byte tier = 0)
{
return AddStatusEffect(new StatusEffect(this.owner, id, magnitude, (uint)(tickMs * 1000), (uint)(durationMs * 1000), tier));
}
public bool AddStatusEffect(StatusEffect newEffect, bool silent = false)
{
// todo: check flags/overwritable and add effect to list
var effect = GetStatusEffectById(newEffect.GetEffectId());
var effect = GetStatusEffectById(newEffect.GetStatusEffectId());
bool canOverwrite = false;
if (effect != null)
{
var overwritable = effect.GetOverwritable();
canOverwrite = (overwritable == (uint)StatusEffectOverwrite.Always) ||
(overwritable == (uint)StatusEffectOverwrite.GreaterOnly && (effect.GetDurationMs() < newEffect.GetDurationMs() || effect.GetMagnitude() < newEffect.GetMagnitude())) ||
(overwritable == (uint)StatusEffectOverwrite.GreaterOrEqualTo && (effect.GetDurationMs() == newEffect.GetDurationMs() || effect.GetMagnitude() == newEffect.GetMagnitude()));
(overwritable == (uint)StatusEffectOverwrite.GreaterOrEqualTo && (effect.GetDurationMs() <= newEffect.GetDurationMs() || effect.GetMagnitude() <= newEffect.GetMagnitude()));
}
if (canOverwrite || effect == null)
@ -63,17 +75,18 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
}
if (canOverwrite)
effects.Remove(effect.GetEffectId());
effects.Remove(newEffect.GetStatusEffectId());
effects.Add(newEffect.GetEffectId(), newEffect);
effects.Add(newEffect.GetStatusEffectId(), newEffect);
// todo: this is retarded..
{
var index = Array.IndexOf(effects.Values.ToArray(), newEffect);
owner.charaWork.status[index] = effect.GetEffectIdForCharaWork();
owner.charaWork.statusShownTime[index] = effect.GetDurationMs() / 1000;
this.owner.zone.BroadcastPacketAroundActor(this.owner, SetActorStatusPacket.BuildPacket(this.owner.actorId, (ushort)index, (ushort)effect.GetEffectId()));
owner.charaWork.status[index] = newEffect.GetStatusId();
owner.charaWork.statusShownTime[index] = (uint)(DateTime.Now.AddMilliseconds(newEffect.GetDurationMs()) - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
this.owner.zone.BroadcastPacketAroundActor(this.owner, SetActorStatusPacket.BuildPacket(this.owner.actorId, (ushort)index, (ushort)newEffect.GetStatusId()));
}
sendUpdate = true;
return true;
}
return false;
@ -81,7 +94,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public void RemoveStatusEffect(StatusEffect effect, bool silent = false)
{
if (effects.ContainsKey(effect.GetEffectId()))
if (effects.ContainsKey(effect.GetStatusEffectId()))
{
// send packet to client with effect remove message
if (!silent || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
@ -92,12 +105,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
// todo: this is retarded..
{
var index = Array.IndexOf(effects.Values.ToArray(), effect);
owner.charaWork.status[index] = effect.GetEffectIdForCharaWork();
owner.charaWork.status[index] = 0;
owner.charaWork.statusShownTime[index] = uint.MaxValue;
this.owner.zone.BroadcastPacketAroundActor(this.owner, SetActorStatusPacket.BuildPacket(owner.actorId, (ushort)index, (ushort)0));
}
// function onLose(actor, effect
LuaEngine.CallLuaStatusEffectFunction(this.owner, effect, "onLose", this.owner, effect);
effects.Remove(effect.GetEffectId());
effects.Remove(effect.GetStatusEffectId());
sendUpdate = true;
}
}
@ -105,7 +120,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
foreach (var effect in effects.Values)
{
if (effect.GetEffectId() == effectId)
if (effect.GetStatusEffectId() == effectId)
{
RemoveStatusEffect(effect, silent);
break;
@ -141,7 +156,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
StatusEffect effect;
if (effects.TryGetValue(id, out effect) && effect.GetEffectId() == id && (tier != 0xFF ? effect.GetTier() == tier : true))
if (effects.TryGetValue(id, out effect) && effect.GetStatusEffectId() == id && (tier != 0xFF ? effect.GetTier() == tier : true))
return effect;
return null;
@ -152,7 +167,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
var list = new List<StatusEffect>();
foreach (var effect in effects.Values)
{
if ((effect.GetFlags() & flag) > 0)
if ((effect.GetFlags() & flag) != 0)
{
list.Add(effect);
}
@ -164,7 +179,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
foreach (var effect in effects.Values)
{
if ((effect.GetFlags() & flag) > 0)
if ((effect.GetFlags() & flag) != 0)
return true;
}
return false;

View File

@ -33,7 +33,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
}
// todo: check weapon delay/haste etc and use that
if ((tick - startTime).Milliseconds >= 0)
if ((tick - startTime).TotalMilliseconds >= 0)
{
OnComplete();
return true;
@ -72,7 +72,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
if (list.Count > 0)
{
// todo: actually check proc rate/random chance of whatever effect
effectId = list[0].GetEffectId();
effectId = list[0].GetStatusEffectId();
}
// todo: which is actually the swing packet
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, 0, 0);

View File

@ -1702,7 +1702,7 @@ namespace FFXIVClassic_Map_Server.Actors
//Update select hotbar slots.
public ActorPropertyPacketUtil GetUpdateHotbarPacket(uint playerActorId, List<ushort> slotsToUpdate)
{
ActorPropertyPacketUtil propPacketUtil = new ActorPropertyPacketUtil("charawork/command", this);
ActorPropertyPacketUtil propPacketUtil = new ActorPropertyPacketUtil("charaWork/command", this);
propPacketUtil.AddProperty("charaWork.commandBorder");
@ -1797,7 +1797,7 @@ namespace FFXIVClassic_Map_Server.Actors
}
}
//Unequip command
else if (trueCommandId == 2700083200)
else if (trueCommandId == 2700083200 && charaWork.command[trueHotbarSlot] != 0)
{
//Need to get the commandId this way because when unequipping an ability the commandId is 0.
commandId = charaWork.command[trueHotbarSlot] ^ 2700083200;

View File

@ -492,7 +492,7 @@ namespace FFXIVClassic_Map_Server.lua
{
bool playerNull = player == null;
if (playerNull && param.Length >= 2)
player = Server.GetWorldManager().GetPCInWorld(param[1] + " " + param[2]);
player = Server.GetWorldManager().GetPCInWorld(param[1].Contains("\"") ? param[1] : param[1] + " " + param[2]);
// load from scripts/commands/gm/ directory
var path = String.Format("./scripts/commands/gm/{0}.lua", cmd.ToLower());