added pool/spawn/genus mod loading

- moved ai helper classes to own folder
This commit is contained in:
Tahir Akhlaq
2017-09-12 01:24:02 +01:00
parent ce5030acd1
commit da621dfc0e
19 changed files with 484 additions and 138 deletions

View File

@@ -115,6 +115,7 @@ namespace FFXIVClassic_Map_Server.Actors
// todo: base this on equip and shit
SetMod((uint)Modifier.AttackRange, 3);
SetMod((uint)Modifier.AttackDelay, (Program.Random.Next(30, 60) * 100));
SetMod((uint)Modifier.Speed, (uint)moveSpeeds[2]);
spawnX = positionX;
spawnY = positionY;
@@ -315,12 +316,10 @@ namespace FFXIVClassic_Map_Server.Actors
packets.Add(BattleActionX00Packet.BuildPacket(actorId, 0x72000062, 0));
packets.Add(BattleActionX01Packet.BuildPacket(actorId, 0x7C000062, 21001, new BattleAction(actorId, 0, 1)));
// this is silly, but looks like state change goes full retard unless theyre sent in order
updateFlags &= ~ActorUpdateFlags.State;
//DoBattleAction(21001, 0x7C000062, new BattleAction(this.actorId, 0, 1, 0, 0, 1)); //Attack Mode
}
// todo: should probably add another flag for battleTemp since all this uses reflection
if ((updateFlags & ActorUpdateFlags.HpTpMp) != 0)
{
var propPacketUtil = new ActorPropertyPacketUtil("charaWork.parameterSave", this);
@@ -497,6 +496,21 @@ namespace FFXIVClassic_Map_Server.Actors
return (byte)((charaWork.parameterSave.hp[0] / charaWork.parameterSave.hpMax[0]) * 100);
}
public void SetHP(uint hp)
{
charaWork.parameterSave.hp[0] = (short)hp;
if (hp > charaWork.parameterSave.hpMax[0])
SetMaxHP(hp);
updateFlags |= ActorUpdateFlags.HpTpMp;
}
public void SetMaxHP(uint hp)
{
charaWork.parameterSave.hpMax[0] = (short)hp;
updateFlags |= ActorUpdateFlags.HpTpMp;
}
// todo: the following functions are virtuals since we want to check hidden item bonuses etc on player for certain conditions
public virtual void AddHP(int hp)
{
@@ -516,6 +530,16 @@ namespace FFXIVClassic_Map_Server.Actors
}
}
public short GetJob()
{
return charaWork.parameterSave.state_mainSkill[0];
}
public short GetLevel()
{
return charaWork.parameterSave.state_mainSkillLevel;
}
public void AddMP(int mp)
{
charaWork.parameterSave.mp = (short)(charaWork.parameterSave.mp + mp).Clamp(ushort.MinValue, charaWork.parameterSave.mpMax);
@@ -527,8 +551,7 @@ namespace FFXIVClassic_Map_Server.Actors
public void AddTP(int tp)
{
tpBase = (ushort)((tpBase + tp).Clamp(0, 3000));
charaWork.parameterTemp.tp = (short)((charaWork.parameterTemp.tp + tp).Clamp(0, 3000));
updateFlags |= ActorUpdateFlags.HpTpMp;
}
@@ -550,9 +573,9 @@ namespace FFXIVClassic_Map_Server.Actors
public void CalculateBaseStats()
{
// todo: apply mods and shit here, get race/level/job and shit
// baseStats.generalParameter[ASIDHOASID] =
}
// todo: should this include stats too?
public void RecalculateStats()
{
if (GetMod((uint)Modifier.Hp) != 0)
@@ -576,7 +599,7 @@ namespace FFXIVClassic_Map_Server.Actors
public virtual float GetSpeed()
{
// todo: for battlenpc/player calculate speed
return moveSpeeds[2] + GetMod((uint)Modifier.Speed);
return GetMod((uint)Modifier.Speed);
}
public virtual void OnAttack(State state, BattleAction action, ref BattleAction error)

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFXIVClassic_Map_Server.actors.chara.npc;
namespace FFXIVClassic_Map_Server.actors.chara
{
class ModifierListEntry
{
public uint id;
public Int64 value;
public ModifierListEntry(uint id, Int64 value)
{
this.id = id;
this.value = value;
}
}
class ModifierList
{
public Dictionary<uint, ModifierListEntry> modList;
public Dictionary<uint, ModifierListEntry> mobModList;
public ModifierList(uint id)
{
modList = new Dictionary<uint, ModifierListEntry>();
mobModList = new Dictionary<uint, ModifierListEntry>();
}
public void AddModifier(uint id, Int64 val, bool isMobMod)
{
var list = isMobMod ? mobModList : modList;
list.Add(id, new ModifierListEntry(id, val));
}
public void SetModifier(uint id, Int64 val, bool isMobMod)
{
var list = isMobMod ? mobModList : modList;
if (list.ContainsKey(id))
list[id].value = val;
else
list.Add(id, new ModifierListEntry(id, val));
}
public Int64 GetModifier(uint id, bool isMobMod)
{
ModifierListEntry retVal;
var list = isMobMod ? mobModList : modList;
if (!list.TryGetValue(id, out retVal))
return 0;
return retVal.value;
}
}
}

View File

@@ -134,7 +134,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public bool CanFollowPath()
{
return pathFind != null && (GetCurrentState() != null || GetCurrentState().CanChangeState());
return pathFind != null && (GetCurrentState() == null || GetCurrentState().CanChangeState());
}
public bool CanChangeState()
@@ -278,6 +278,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (controller != null)
controller.UseItem(target, slot, itemId);
}
public void InternalChangeTarget(Character target)
{
// targets are changed in the controller

View File

@@ -8,6 +8,8 @@ using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.actors.area;
using FFXIVClassic_Map_Server.utils;
using FFXIVClassic_Map_Server.actors.chara.ai.state;
using FFXIVClassic_Map_Server.actors.chara.npc;
namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
{
@@ -132,10 +134,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
Engage(owner.hateContainer.GetMostHatedTarget());
return;
}
//else if (owner.currentLockedTarget != 0)
//{
// ChangeTarget(Server.GetWorldManager().GetActorInWorld(owner.currentLockedTarget).GetAsCharacter());
//}
if (tick >= waitTime)
{
@@ -155,7 +153,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
waitTime = tick.AddSeconds(10);
owner.OnRoam(tick);
if (!owner.aiContainer.pathFind.IsFollowingPath())
if (!owner.aiContainer.pathFind.IsFollowingPath() && CanMoveForward(0.0f))
{
// will move on next tick
owner.aiContainer.pathFind.SetPathFlags(PathFindFlags.None);
@@ -166,22 +164,25 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
if (tick >= neutralTime)
{
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
if (!owner.neutral && owner.IsAlive())
{
if (!owner.isMovingToSpawn && owner.aiContainer.pathFind.AtPoint() && owner.detectionType != DetectionType.None)
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
{
uint levelDifference = (uint)Math.Abs(owner.charaWork.parameterSave.state_mainSkillLevel - player.charaWork.parameterSave.state_mainSkillLevel);
if (levelDifference <= 10 || (owner.detectionType & DetectionType.IgnoreLevelDifference) != 0 && CanAggroTarget(player))
if (!owner.isMovingToSpawn && owner.aiContainer.pathFind.AtPoint() && owner.detectionType != DetectionType.None)
{
owner.hateContainer.AddBaseHate(player);
break;
uint levelDifference = (uint)Math.Abs(owner.charaWork.parameterSave.state_mainSkillLevel - player.charaWork.parameterSave.state_mainSkillLevel);
if (levelDifference <= 10 || (owner.detectionType & DetectionType.IgnoreLevelDifference) != 0 && CanAggroTarget(player))
{
owner.hateContainer.AddBaseHate(player);
break;
}
}
}
}
}
if (owner.aiContainer.pathFind.IsFollowingPath())
if (owner.aiContainer.pathFind.IsFollowingPath() && owner.aiContainer.CanFollowPath())
{
owner.aiContainer.pathFind.FollowPath();
}
@@ -328,6 +329,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
bool hasInvisible = false;
bool isFacing = owner.IsFacing(target);
// use the mobmod sight range before defaulting to 20 yalms
if (detectSight && !hasInvisible && isFacing && distance < owner.GetMobMod((uint)MobModifier.SightRange))
return CanSeePoint(target.positionX, target.positionY, target.positionZ);
// todo: check line of sight and aggroTypes
if (distance > 20)
{
@@ -341,10 +346,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
}
if ((owner.detectionType & DetectionType.LowHp) != 0 && target.GetHPP() < 75)
if ((owner.detectionType & DetectionType.Sound) != 0 && !hasSneak && distance < owner.GetMobMod((uint)MobModifier.SoundRange))
return CanSeePoint(target.positionX, target.positionY, target.positionZ);
if (detectSight && !hasInvisible && isFacing)
if ((owner.detectionType & DetectionType.Magic) != 0 && target.aiContainer.IsCurrentState<MagicState>())
return CanSeePoint(target.positionX, target.positionY, target.positionZ);
if ((owner.detectionType & DetectionType.LowHp) != 0 && target.GetHPP() < 75)
return CanSeePoint(target.positionX, target.positionY, target.positionZ);
return false;

View File

@@ -73,18 +73,18 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnInterrupt()
{
// todo: send paralyzed/sleep message etc.
if (errorResult != null)
{
owner.zone.BroadcastPacketAroundActor(owner, BattleActionX01Packet.BuildPacket(errorResult.targetId, errorResult.animation, 0x765D, errorResult));
errorResult = null;
}
}
public override void OnComplete()
{
// todo: possible underflow
BattleAction action = new BattleAction(target.actorId, 0x765D, (uint) HitEffect.Hit, 0, (byte) HitDirection.None);
errorResult = null;
//var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);
// HitDirection (auto attack shouldnt need this afaik)
// todo: implement auto attack damage bonus in Character.OnAttack
/*
≪Auto-attack Damage Bonus≫
@@ -98,30 +98,22 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
Thaumaturge Mind Piety
* The above damage bonus also applies to “Shot” attacks by archers.
*/
// handle paralyze/intimidate/sleep/whatever in Character.OnAttack
owner.OnAttack(this, action, ref errorResult);
// handle paralyze/intimidate/sleep/whatever in character thing
owner.DoBattleAction((ushort)BattleActionX01PacketCommand.Attack, action.animation, errorResult == null ? action : errorResult);
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
}
public override void TryInterrupt()
{
if (owner.statusEffects.HasStatusEffectsByFlag((uint)StatusEffectFlags.PreventAction))
{
// todo: sometimes paralyze can let you attack, get random percentage of actually letting you attack
// todo: sometimes paralyze can let you attack, calculate proc rate
var list = owner.statusEffects.GetStatusEffectsByFlag((uint)StatusEffectFlags.PreventAction);
uint statusId = 0;
if (list.Count > 0)
{
// todo: actually check proc rate/random chance of whatever effect
statusId = list[0].GetStatusId();
}
// todo: which is actually the swing packet
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, statusId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
//owner.zone.BroadcastPacketAroundActor(owner, errorPacket);
//errorPacket = null;
interrupt = true;
return;
}
@@ -147,7 +139,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
return false;
}
// todo: shouldnt need to check if owner is dead since all states would be cleared
if (owner.aiContainer.IsDead() || target.aiContainer.IsDead())
if (owner.IsDead() || target.IsDead())
{
if (owner is BattleNpc)
((BattleNpc)owner).hateContainer.ClearHate(target);

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFXIVClassic_Map_Server.Actors;
namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{
class InactiveState : State
{
private DateTime endTime;
private uint durationMs;
public InactiveState(Character owner, uint durationMs, bool canChangeState) :
base(owner, null)
{
if (!canChangeState)
owner.aiContainer.InterruptStates();
this.durationMs = durationMs;
endTime = DateTime.Now.AddMilliseconds(durationMs);
}
public override bool Update(DateTime tick)
{
if (durationMs == 0)
{
if (owner.IsDead())
return true;
if (!owner.statusEffects.HasStatusEffectsByFlag(StatusEffectFlags.PreventAction))
return true;
}
if (durationMs != 0 && tick > endTime)
{
return true;
}
return false;
}
}
}

View File

@@ -63,6 +63,12 @@ namespace FFXIVClassic_Map_Server.Actors
public uint spellListId, skillListId, dropListId;
public Dictionary<uint, BattleCommand> skillList = new Dictionary<uint, BattleCommand>();
public Dictionary<uint, BattleCommand> spellList = new Dictionary<uint, BattleCommand>();
public uint poolId, genusId;
public ModifierList poolMods;
public ModifierList genusMods;
public ModifierList spawnMods;
private Dictionary<MobModifier, Int64> mobModifiers = new Dictionary<MobModifier, Int64>();
public BattleNpc(int actorNumber, ActorClass actorClass, string uniqueId, Area spawnedArea, float posX, float posY, float posZ, float rot,
@@ -326,9 +332,6 @@ namespace FFXIVClassic_Map_Server.Actors
public void OnRoam(DateTime tick)
{
// todo: move this to battlenpccontroller..
bool foundActor = false;
// leash back to spawn
if (!IsCloseToSpawn())
{
@@ -345,7 +348,15 @@ namespace FFXIVClassic_Map_Server.Actors
}
else
{
this.isMovingToSpawn = false;
// recover hp
if (GetHPP() < 100)
{
AddHP(GetMaxHP() / 10);
}
else
{
this.isMovingToSpawn = false;
}
lua.LuaEngine.CallLuaBattleFunction(this, "onRoam", this);
}
}
@@ -368,7 +379,6 @@ namespace FFXIVClassic_Map_Server.Actors
public override void OnCast(State state, BattleAction[] actions, ref BattleAction[] errors)
{
base.OnCast(state, actions, ref errors);
}
public override void OnAbility(State state, BattleAction[] actions, ref BattleAction[] errors)