public static void Calc(EntityInfo entity) { ResetBaseProperty(entity); RefixAttrByImpact(entity); int hpMax = entity.GetActualProperty().HpMax; entity.GetActualProperty().SetHpMax(Operate_Type.OT_Absolute, hpMax); }
private void OnDamage(int receiver, int caster, bool isNormalDamage, bool isCritical, int hpDamage, int npDamage) { if (receiver == LeaderID && caster > 0) { bool newSelect = true; if (null != SelectedTarget) { EntityInfo curTarget = GetEntityById(ClientModule.Instance.SelectedTarget.TargetId); if (curTarget == SelectedTarget.Target) { newSelect = false; } } if (newSelect) { SetLockTarget(caster); } } EntityInfo entity = GetEntityById(receiver); EntityInfo casterNpc = GetEntityById(caster); while (null != casterNpc && casterNpc.SummonerId > 0) { casterNpc = GetEntityById(casterNpc.SummonerId); if (null != casterNpc) { caster = casterNpc.GetId(); } } if (null != entity) { if (hpDamage != 0) { float hp = (float)entity.Hp / entity.GetActualProperty().HpMax; Utility.EventSystem.Publish("ui_actor_hp", "ui", entity.GetId(), hp); //if (receiver == LeaderID || caster == LeaderID) { Utility.EventSystem.Publish("ui_show_hp_num", "ui", entity.GetId(), -hpDamage); //} if (caster == LeaderID) { EntityViewModel view = EntityController.Instance.GetEntityViewById(receiver); if (view != null) { view.SetRedEdge(1.0f); } } } if (npDamage != 0) { float mp = (float)entity.Energy / entity.GetActualProperty().EnergyMax; Utility.EventSystem.Publish("ui_actor_mp", "ui", entity.GetId(), mp, -npDamage); //ClientModuleUtility.EventSystem.Publish("ui_show_mp_num", "ui", entity.GetId(), -npDamage); } } }
public bool CastSkill(int objId, int skillId) { bool ret = false; EntityInfo obj = GetEntityById(objId); if (null != obj) { SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { if (obj.Energy >= obj.GetActualProperty().EnergyMax) { if (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds())) { int targetId = 0; if (null != SelectedTarget) { targetId = SelectedTarget.TargetId; } if (IsRoomScene) { Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir()); } else { AiStateInfo aiInfo = obj.GetAiStateInfo(); aiInfo.Target = targetId; if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader) { AiData_Leader data = aiInfo.AiDatas.GetData <AiData_Leader>(); if (null == data) { data = new AiData_Leader(); aiInfo.AiDatas.AddData(data); } data.ManualSkillId = skillId; } else { AiData_General data = aiInfo.AiDatas.GetData <AiData_General>(); if (null == data) { data = new AiData_General(); aiInfo.AiDatas.AddData(data); } data.ManualSkillId = skillId; } aiInfo.ChangeToState((int)AiStateId.SkillCommand); } ret = true; } } } } return(ret); }
public float GetNpcMp(int objID) { EntityInfo entity = GetEntityById(objID); if (entity != null) { float mp = (float)entity.Energy / entity.GetActualProperty().EnergyMax; return(mp); } return(0); }
public CharacterProperty GetGameObjectProperty(int id) { CharacterProperty prop = null; EntityInfo entity = GetEntityById(id); if (null != entity) { prop = entity.GetActualProperty(); } return(prop); }
public void RefixCharacterProperty(EntityInfo entity) { if (DamageData.AddAttack != 0) { entity.GetActualProperty().SetAttackBase(Operate_Type.OT_Relative, DamageData.AddAttack); } if (DamageData.AddDefence != 0) { entity.GetActualProperty().SetDefenceBase(Operate_Type.OT_Relative, DamageData.AddDefence); } if (DamageData.AddRps != 0) { entity.GetActualProperty().SetRps(Operate_Type.OT_Relative, DamageData.AddRps); } if (DamageData.AddCritical != 0) { entity.GetActualProperty().SetCritical(Operate_Type.OT_Relative, DamageData.AddCritical); } if (DamageData.AddCriticalPow != 0) { entity.GetActualProperty().SetCriticalPow(Operate_Type.OT_Relative, DamageData.AddCriticalPow); } if (Math.Abs(DamageData.AddSpeed) > Geometry.c_FloatPrecision) { entity.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Relative, DamageData.AddSpeed); } }
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.GetActualProperty().MoveSpeed; float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; User user = obj.CustomData as User; if (null != user) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
internal static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc) { ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove(); if (npc.GetMovementStateInfo().IsMoving) { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.velocity = ProtoHelper.EncodeFloat(npc.GetActualProperty().MoveSpeed); ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition; npcMoveBuilder.target_pos = ProtoHelper.EncodePosition2D(targetPos.X, targetPos.Z); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } else { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } return npcMoveBuilder; }
internal static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc) { ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove(); if (npc.GetMovementStateInfo().IsMoving) { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.velocity = ProtoHelper.EncodeFloat(npc.GetActualProperty().MoveSpeed); ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition; npcMoveBuilder.target_pos = ProtoHelper.EncodePosition2D(targetPos.X, targetPos.Z); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } else { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } return(npcMoveBuilder); }
internal static void DoPursuitCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 200) { EntityInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.Target); if (null != target) { float minDist = entity.GetRadius() + target.GetRadius(); float dist = (float)entity.GetActualProperty().AttackRange + minDist; float distGoHome = entity.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); float dir = Geometry.GetYRadian(new Vector2(targetPos.X, targetPos.Z), new Vector2(srcPos.X, srcPos.Z)); targetPos.X += (float)(minDist * Math.Sin(dir)); targetPos.Z += (float)(minDist * Math.Cos(dir)); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { logic.AiSendStoryMessage(entity, "npc_pursuit_finish:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_pursuit_finish", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } else { logic.NotifyAiPursue(entity, targetPos); } } else { logic.AiSendStoryMessage(entity, "npc_pursuit_exit:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_pursuit_exit", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } }
internal void Create(EntityInfo entity) { if (null != entity) { m_Entity = entity; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Entity.GetId(), m_Entity.GetModel(), pos.X, pos.Y, pos.Z, dir, m_Entity.Scale, m_Entity.GetRadius(), m_Entity.GetActualProperty().MoveSpeed); if (null != Actor) { m_Agent = Actor.GetComponent <NavMeshAgent>(); if (m_Agent == null) { m_Agent = Actor.AddComponent <NavMeshAgent>(); m_Agent.angularSpeed = c_AngularSpeed; m_Agent.acceleration = c_Acceleration; m_Agent.radius = entity.GetRadius(); m_Agent.speed = entity.GetActualProperty().MoveSpeed; m_Agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; m_Agent.ResetPath(); } m_Animator = Actor.GetComponentInChildren <Animator>(); EntityDrawGizmos gizmos = Actor.GetComponent <EntityDrawGizmos>(); if (null == gizmos) { gizmos = Actor.AddComponent <EntityDrawGizmos>(); gizmos.npcInfo = m_Entity; } else { gizmos.npcInfo = m_Entity; } SetMoveAgentEnable(true); } } }
internal void Create(EntityInfo entity) { if (null != entity) { m_Entity = entity; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Entity.GetId(), m_Entity.GetModel(), pos.X, pos.Y, pos.Z, dir, m_Entity.Scale, m_Entity.GetRadius(), m_Entity.GetActualProperty().MoveSpeed); if (null != Actor) { m_Agent = Actor.GetComponent<NavMeshAgent>(); if (m_Agent == null) { m_Agent = Actor.AddComponent<NavMeshAgent>(); m_Agent.angularSpeed = c_AngularSpeed; m_Agent.acceleration = c_Acceleration; m_Agent.radius = entity.GetRadius(); m_Agent.speed = entity.GetActualProperty().MoveSpeed; m_Agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; m_Agent.ResetPath(); } m_Animator = Actor.GetComponentInChildren<Animator>(); EntityDrawGizmos gizmos = Actor.GetComponent<EntityDrawGizmos>(); if (null == gizmos) { gizmos = Actor.AddComponent<EntityDrawGizmos>(); gizmos.npcInfo = m_Entity; } else { gizmos.npcInfo = m_Entity; } SetMoveAgentEnable(true); } } }
private void TickEntities() { m_DeletedEntities.Clear(); for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; info.RetireAttackerInfos(60000); if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged) { AttrCalculator.Calc(info); info.LevelChanged = false; info.GetSkillStateInfo().BuffChanged = false; } if (info.IsBorning) { if (info.BornTime <= 0) { SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.BornSkillId); if (info.BornSkillId > 0 && null != skillInfo) { info.BornTime = TimeUtility.GetLocalMilliseconds(); m_SkillSystem.StartSkill(info.GetId(), skillInfo.ConfigData, 0); } else { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } } else if (info.BornTime + info.BornTimeout < TimeUtility.GetLocalMilliseconds()) { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } } if (info.IsDead() && !info.NeedDelete) { if (info.DeadTime <= 0) { CalcKillIncome(info); //发送npc死亡消息 Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead(); npcDeadBuilder.npc_id = info.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder); SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.DeadSkillId); if (info.DeadSkillId > 0 && null != skillInfo) { info.DeadTime = TimeUtility.GetLocalMilliseconds(); m_SkillSystem.StopAllSkill(info.GetId(), true, false, true); m_SkillSystem.StartSkill(info.GetId(), skillInfo.ConfigData, 0); OnEntityKilled(info); } else { if (null == info.CustomData as User) { info.DeadTime = 0; info.NeedDelete = true; OnEntityKilled(info); } else { info.DeadTime = TimeUtility.GetLocalMilliseconds(); } } } else { if (null == info.CustomData as User && info.DeadTime + info.DeadTimeout < TimeUtility.GetLocalMilliseconds()) { info.DeadTime = 0; info.NeedDelete = true; //重新发送npc死亡消息 Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead(); npcDeadBuilder.npc_id = info.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder); } else if (null != info.CustomData as User && info.DeadTime + info.ReliveTimeout < TimeUtility.GetLocalMilliseconds()) { info.DeadTime = 0; info.SetHp(Operate_Type.OT_Absolute, info.GetActualProperty().HpMax); info.SetEnergy(Operate_Type.OT_Absolute, info.GetActualProperty().EnergyMax); Msg_RC_SyncProperty npcProp = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, npcProp); } } } if (info.NeedDelete) { m_DeletedEntities.Add(info); } } if (m_DeletedEntities.Count > 0) { int enemyCt = 0; int friendCt = 0; Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc(); for (int i = 0; i < m_DeletedEntities.Count; ++i) { EntityInfo ni = m_DeletedEntities[i]; if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId())) { ++enemyCt; } else if (CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId())) { ++friendCt; } //发送npc消失消息 destroyNpcBuilder.npc_id = ni.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_DestroyNpc, destroyNpcBuilder); DestroyEntity(ni); } TryAllKilledOrAllDied(enemyCt > 0, friendCt > 0); } m_EntityMgr.ExecuteDelayAdd(); }