abilities now use correct animation id (<3 azia)

- did stuff with magicstate/attackstate
- fixed status effect tick
- added regen status (todo: actually populate the table and use that name instead of enum's)
- added baseStats to char (todo: add bonuses and stuff on top of those, set charaWork values to the calculated ones + bonus)
This commit is contained in:
Tahir Akhlaq
2017-08-25 03:52:43 +01:00
parent 88abd59ec3
commit 11bbb023d9
25 changed files with 426 additions and 235 deletions

View File

@@ -295,12 +295,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public void InternalCast(Character target, uint spellId)
{
ChangeState(new MagicState(owner, target, (ushort)spellId));
}
public void InternalWeaponSkill(Character target, uint weaponSkillId)
{
ChangeState(new WeaponSkillState(owner, target, (ushort)weaponSkillId));
}
public void InternalMobSkill(Character target, uint mobSkillId)
@@ -310,7 +310,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public void InternalDie(DateTime tick, uint timeToFadeout)
{
if (true) return;
ClearStates();
Disengage();
ForceChangeState(new DeathState(owner, tick, timeToFadeout));

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFXIVClassic_Map_Server.actors.chara.player;
namespace FFXIVClassic_Map_Server.actors.chara.ai
{
@@ -42,7 +43,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
class Ability
{
public ushort abilityId;
public ushort id;
public string name;
public byte job;
public byte level;
@@ -65,14 +66,17 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public ushort modelAnimation;
public ushort animationDurationSeconds;
public uint battleAnimation;
public ushort worldMasterTextId;
public uint param;
public TargetFind targetFind;
public Ability(ushort id, string name)
{
this.abilityId = id;
this.id = id;
this.name = name;
this.range = -1;
this.range = 0;
}
public Ability Clone()
@@ -90,10 +94,11 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return castTimeSeconds == 0;
}
public bool CanPlayerUse(Character user, Character target)
public bool IsValidTarget(Character user, Character target)
{
// todo: set box length..
targetFind = new TargetFind(user);
if (aoeType == TargetFindAOEType.Box)
{
// todo: read box width from sql
@@ -103,7 +108,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
targetFind.SetAOEType(validTarget, aoeType, range, 40);
}
return false;
return targetFind.CanTarget(target, true, true);
}
}
}

View File

@@ -91,7 +91,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
var dest = owner.FindRandomPoint(x, y, z, minRange, maxRange);
// todo: this is dumb..
distanceFromPoint = owner.meleeRange;
distanceFromPoint = owner.GetAttackRange();
PreparePath(dest.X, dest.Y, dest.Z);
}
@@ -148,14 +148,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
float speed = GetSpeed();
float stepDistance = speed;
float stepDistance = speed / 3;
float distanceTo = Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, point.X, point.Y, point.Z);
owner.LookAt(point.X, point.Y);
if (distanceTo <= distanceFromPoint + stepDistance)
{
if (distanceFromPoint <= 1.5f)
if (distanceFromPoint <= owner.GetAttackRange())
{
owner.QueuePositionUpdate(point);
}

View File

@@ -419,7 +419,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).TotalMilliseconds >= tickMs)
if (tickMs != 0 && (tick - lastTick).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
@@ -443,7 +443,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public Character GetSource()
{
return source;
return source ?? owner;
}
public uint GetStatusEffectId()

View File

@@ -46,18 +46,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (sendUpdate)
{
var propPacketUtil = new ActorPropertyPacketUtil("charaWork.status", owner);
//Status Times
for (int i = 0; i < owner.charaWork.statusShownTime.Length; i++)
{
if (owner.charaWork.status[i] != 0xFFFF && owner.charaWork.status[i] != 0)
propPacketUtil.AddProperty(String.Format("charaWork.status[{0}]", i));
if (owner.charaWork.statusShownTime[i] != 0xFFFFFFFF)
propPacketUtil.AddProperty(String.Format("charaWork.statusShownTime[{0}]", i));
}
owner.zone.BroadcastPacketsAroundActor(owner, propPacketUtil.Done());
owner.zone.BroadcastPacketsAroundActor(owner, owner.GetActorStatusPackets());
sendUpdate = false;
}
}
@@ -97,7 +86,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
// todo: send packet to client with effect added message
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, owner.actorId, 0, newEffect.GetStatusEffectId(), 0, newEffect.GetStatusId(), 0, 0));
player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, newEffect.GetSource().actorId, newEffect.GetOwner().actorId, 0x7678, 0, 0, newEffect.GetStatusId(), 0, 0));
}
// wont send a message about losing effect here
@@ -115,8 +104,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
owner.charaWork.statusShownTime[index] = Utils.UnixTimeStampUTC() + (newEffect.GetDurationMs() / 1000);
this.owner.zone.BroadcastPacketAroundActor(this.owner, SetActorStatusPacket.BuildPacket(this.owner.actorId, (ushort)index, (ushort)newEffect.GetStatusId()));
}
owner.RecalculateHpMpTp();
sendUpdate = true;
{
owner.zone.BroadcastPacketsAroundActor(owner, owner.GetActorStatusPackets());
}
owner.RecalculateStats();
}
return true;
}
@@ -130,9 +121,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
// send packet to client with effect remove message
if (!silent || !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
{
// todo: send packet to client with effect removed message
//foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
// player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, effect.GetSource().actorId, owner.actorId, 0, effect.GetStatusEffectId(), 0, effect.GetStatusId(), 0, 0));
// todo: send packet to client with effect added message
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, owner.actorId, 0x7679, 0, 0, effect.GetStatusId(), 0, 0));
}
// todo: this is retarded..
@@ -145,7 +136,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
// function onLose(actor, effect)
LuaEngine.CallLuaStatusEffectFunction(this.owner, effect, "onLose", this.owner, effect);
effects.Remove(effect.GetStatusEffectId());
owner.RecalculateHpMpTp();
owner.RecalculateStats();
sendUpdate = true;
}
}

View File

@@ -82,7 +82,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
if (Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, target.positionX, target.positionY, target.positionZ) > 10)
{
owner.aiContainer.pathFind.SetPathFlags(PathFindFlags.None);
owner.aiContainer.pathFind.PathInRange(target.positionX, target.positionY, target.positionZ, 1.5f, owner.meleeRange);
owner.aiContainer.pathFind.PathInRange(target.positionX, target.positionY, target.positionZ, 1.5f, owner.GetAttackRange());
ChangeTarget(target);
return false;
}
@@ -114,22 +114,22 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
public override void Cast(Character target, uint spellId)
{
// todo:
}
public override void Ability(Character target, uint abilityId)
{
// todo:
}
public override void RangedAttack(Character target)
{
// todo:
}
public override void MonsterSkill(Character target, uint mobSkillId)
{
// todo:
}
private void DoRoamTick(DateTime tick)
@@ -202,7 +202,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
var targetPos = new Vector3(owner.target.positionX, owner.target.positionY, owner.target.positionZ);
var distance = Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, targetPos.X, targetPos.Y, targetPos.Z);
if (distance > owner.meleeRange - 0.2f || owner.aiContainer.CanFollowPath())
if (distance > owner.GetAttackRange() - 0.2f || owner.aiContainer.CanFollowPath())
{
if (CanMoveForward(distance))
{

View File

@@ -63,7 +63,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
public override void Cast(Character target, uint spellId)
{
owner.aiContainer.InternalCast(target, spellId);
}
public override void Ability(Character target, uint abilityId)

View File

@@ -100,7 +100,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
player.QueuePacket(packet);
}
}
//target.DelHP((short)damage);
target.DelHP((short)damage);
attackTime = attackTime.AddMilliseconds(owner.GetAttackDelayMs());
owner.LookAt(target);
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
@@ -150,9 +150,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
return false;
}
// todo: use a mod for melee range
else if (Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, target.positionX, target.positionY, target.positionZ) > owner.meleeRange)
else if (Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, target.positionX, target.positionY, target.positionZ) > owner.GetAttackRange())
{
//owner.aiContainer.GetpathFind?.PreparePath(target.positionX, target.positionY, target.positionZ, 2.5f, 4);
if (owner.currentSubState == SetActorStatePacket.SUB_STATE_PLAYER)
{
((Player)owner).SendGameMessage(Server.GetWorldManager().GetActor(), 32539, 0x20);
}
return false;
}
return true;

View File

@@ -28,7 +28,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
if (owner.currentSubState == SetActorStatePacket.SUB_STATE_PLAYER)
{
// todo: mark for zoning and remove after main loop
owner.ChangeState(SetActorStatePacket.MAIN_STATE_PASSIVE);
owner.Spawn(Program.Tick);
//Server.GetWorldManager().DoZoneChange(((Player)owner), 244, null, 0, 15, -160.048f, 0, -165.737f, 0.0f);
}
else

View File

@@ -13,6 +13,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{
private Ability spell;
private uint cost;
private Vector3 startPos;
public MagicState(Character owner, Character target, ushort spellId) :
base(owner, target)
@@ -20,53 +22,132 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
this.startTime = DateTime.Now;
// todo: lookup spell from global table
this.spell = Server.GetWorldManager().GetAbility(spellId);
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellPrepare", owner, target, spell);
if (spell != null)
if (spell != null && returnCode == 0)
{
if (spell.CanPlayerUse(owner, target))
// todo: hp/mp shit should be taken care of in scripts, not here
// todo: Azia can fix, check the recast time and send error
if (!spell.IsValidTarget(owner, target))
{
// todo: error message
interrupt = true;
}
else if ((spell.mpCost = (ushort)Math.Ceiling((8000 + (owner.charaWork.parameterSave.state_mainSkillLevel - 70) * 500) * (spell.mpCost * 0.001))) > owner.GetMP())
{
// todo: error message
interrupt = true;
}
else if (spell.level > owner.charaWork.parameterSave.state_mainSkillLevel)
{
// todo: error message
}
else if (false /*spell.requirements & */)
{
// todo: error message
}
else
{
OnStart();
}
}
else
{
// todo: fuckin retarded. enum log messages somewhere (prolly isnt even right param)
if (owner is Player)
((Player)owner).SendGameMessage(Server.GetWorldManager().GetActor(), (ushort)(returnCode == -1 ? 32539 : returnCode), 0x20);
interrupt = true;
}
}
public override void OnStart()
{
// todo: check within attack range
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellStart", owner, target, spell);
owner.LookAt(target);
if (returnCode != 0)
{
interrupt = true;
errorPacket = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, owner.actorId, 0, 0, (ushort)(returnCode == -1 ? 32539 : returnCode), spell.id, 0, 1);
}
else
{
// todo: check within attack range
startPos = owner.GetPosAsVector3();
owner.LookAt(target);
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
{
// todo: this is retarded, prolly doesnt do what i think its gonna do
player.QueuePacket(BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, target != null ? target.actorId : 0xC0000000, spell.battleAnimation, spell.effectAnimation, 0, spell.id, 0, (byte)spell.castTimeSeconds));
}
}
}
public override bool Update(DateTime tick)
{
TryInterrupt();
if (interrupt)
if (spell != null)
{
OnInterrupt();
return true;
}
TryInterrupt();
// todo: check weapon delay/haste etc and use that
if ((tick - startTime).TotalMilliseconds >= 0)
{
OnComplete();
return true;
if (interrupt)
{
OnInterrupt();
return true;
}
// todo: check weapon delay/haste etc and use that
var actualCastTime = spell.castTimeSeconds;
if ((tick - startTime).TotalSeconds >= spell.castTimeSeconds)
{
OnComplete();
return true;
}
return false;
}
return false;
return true;
}
public override void OnInterrupt()
{
// todo: send paralyzed/sleep message etc.
if (errorPacket != null)
{
owner.zone.BroadcastPacketAroundActor(owner, errorPacket);
}
}
public override void OnComplete()
{
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
spell.targetFind.FindWithinArea(target, spell.validTarget);
isCompleted = true;
List<SubPacket> packets = new List<SubPacket>();
foreach (var chara in spell.targetFind.GetTargets())
{
// todo: calculate shit, do shit
bool landed = true;
var amount = lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellFinish", owner, target, spell);
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
{
player.QueuePacket(BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, chara.actorId, spell.battleAnimation, spell.effectAnimation, spell.worldMasterTextId, spell.id, (ushort)spell.param, 1));
}
if (chara is BattleNpc)
{
((BattleNpc)chara).hateContainer.UpdateHate(owner, amount);
}
}
}
public override void TryInterrupt()
{
if (interrupt)
return;
if (owner.statusEffects.HasStatusEffectsByFlag((uint)StatusEffectFlags.PreventAction))
{
// todo: sometimes paralyze can let you attack, get random percentage of actually letting you attack
@@ -85,10 +166,17 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
return;
}
interrupt = !CanAttack();
if (Utils.DistanceSquared(owner.GetPosAsVector3(), startPos) > 4.0f)
{
// todo: send interrupt packet
interrupt = true;
return;
}
interrupt = !CanCast();
}
private bool CanAttack()
private bool CanCast()
{
if (target == null)
{
@@ -103,9 +191,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{
return false;
}
else if (Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, target.positionX, target.positionY, target.positionZ) >= 7.5f)
else if (Utils.Distance(owner.positionX, owner.positionY, owner.positionZ, target.positionX, target.positionY, target.positionZ) > spell.range)
{
owner.aiContainer.pathFind?.PreparePath(target.positionX, target.positionY, target.positionZ, 2.5f, 4);
if (owner.currentSubState == SetActorStatePacket.SUB_STATE_PLAYER)
{
((Player)owner).SendGameMessage(Server.GetWorldManager().GetActor(), 32539, 0x20);
}
return false;
}
return true;

View File

@@ -23,5 +23,11 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.utils
}
defender.DelHP((short)damage);
}
public static int CalculateSpellDamage(Character attacker, Character defender, Ability spell)
{
// todo: spell formulas and stuff (stoneskin, mods, stats, etc)
return 69;
}
}
}