private void OnSyncHeroHpMp(KProtoBuf buf) { S2C_SYNC_HERO_HPMP respond = buf as S2C_SYNC_HERO_HPMP; SceneEntity hero = GetSceneObject(respond.heroID); if (hero) { hero.Hp = respond.hp; hero.Mp = respond.mp; if (SceneLogic.GetInstance().mainHero == hero) { EventDispatcher.GameWorld.DispatchEvent(ControllerCommand.CHANGE_PLAYER_HP_MP); } if (SceneLogic.GetInstance().mainHero.property.target == hero && hero.heroSetting.MonsterGrade > KMonsterGrade.mgNormal)//主角正打boss { EventDispatcher.GameWorld.DispatchEvent(ControllerCommand.ATTACK_BOSS); } if (hero.property.fightHp < hero.Hp) { hero.property.fightHp = hero.Hp; } } }
public static SceneLogic GetInstance() { if (instance == null) { instance = new SceneLogic(); } return(instance); }
private void NotifyCastSkillFail(KProtoBuf buf) { S2C_CAST_SKILL_FAIL_NOTIFY respond = buf as S2C_CAST_SKILL_FAIL_NOTIFY; Debug.LogWarning("NotifyCastSkillFail "); if (SceneLogic.GetInstance().MainHero.ActiveAction is ActionWaitSkill) { MainHero.DispatchEvent(ControllerCommand.FinishImmediate); } }
//public static DebugCounter debugCounter = new DebugCounter(); public void AddHero(S2C_SYNC_NEW_HERO hero) { //debugCounter.Restart(); //debugCounter.AddMark("heroSet"); KSceneObjectType sot = KSceneObjectType.sotHero; KHeroObjectType hot = KHeroObjectType.hotInvalid; KDoodadType dt = KDoodadType.dddInvalid; KHeroSetting heroSetting = KConfigFileManager.GetInstance().heroSetting.getData(hero.wNpcIDOrJob.ToString()); log.Assert(heroSetting != null); hot = heroSetting.HeroType; string Name = ""; string Title = ""; switch (heroSetting.HeroType) { case KHeroObjectType.hotNpc: { if (!npcidToSceneidDic.ContainsKey((int)heroSetting.ID)) { npcidToSceneidDic.Add((int)heroSetting.ID, hero.id); } else { npcidToSceneidDic[(int)heroSetting.ID] = hero.id; } Name = heroSetting.Name; Title = heroSetting.Title; } break; case KHeroObjectType.hotMonster: { Name = heroSetting.Name; } break; case KHeroObjectType.hotPlayer: { Assets.Scripts.Model.Player.Player newPlayerInfo = PlayerManager.GetInstance().GetPlayer(hero.uOwnerID); if (newPlayerInfo != null) { Name = newPlayerInfo.PlayerName; } else { Name = "not init"; } } break; default: { throw new ArgumentException("error heroSetting.HeroType = " + heroSetting.HeroType + " at hero which id = " + hero.id + " uOwnerID = " + hero.uOwnerID); } } if (hero.uOwnerID == PlayerManager.GetInstance().MajorPlayer.PlayerID) { PlayerManager.GetInstance().MajorPlayer.hero = hero.id; EventDispatcher.GameWorld.Dispath(ControllerCommand.CHANGE_NICKNAME, PlayerManager.GetInstance().MajorPlayer.PlayerName); } SceneEntity entity = CreateSceneObject(hero.id, sot, hot, dt, MapUtils.GetMetreFromInt(hero.posX, hero.posY), hero.uOwnerID); entity.heroSetting = heroSetting; if (heroSetting.HeroType == KHeroObjectType.hotMonster && hero.bNewHero != 0) { entity.property.bNewHero = true; } entity.Init(); entity.DispatchEvent(ControllerCommand.SET_SPEED, hero.moveSpeed); entity.property.isDeaded = entity.property.isDeadTemp = (hero.moveState == (byte)KMoveState.mosDeath); entity.property.Face = hero.faceDir; entity.property.maxHp = (int)hero.MaxHP; entity.property.maxMp = (int)hero.MaxMP; entity.property.fightHp = entity.property.hp = (int)hero.HP; entity.property.mp = (int)hero.MP; entity.AttackSpeed = (int)hero.attackSpeed; entity.transform.localScale = new Vector3(heroSetting.Scale, heroSetting.Scale, heroSetting.Scale); entity.property.characterController.size = new Vector3(0.7f, 2f, 0.7f); entity.property.characterController.center = new Vector3(0, 1, 0); if (hot == KHeroObjectType.hotPlayer && hero.uOwnerID == PlayerManager.GetInstance().MajorPlayer.PlayerID) { SceneLogic.GetInstance().MainHero = entity; } Vector3 destination = MapUtils.GetMetreFromInt(hero.desX, hero.desZ, hero.desY); if (hero.desX == 0 && hero.desZ == 0 && hero.desY == 0) { destination = MapUtils.GetMetreFromInt(hero.posX, hero.posY); } entity.TabID = hero.wNpcIDOrJob; entity.Job = KJob.jobNone; if (entity.HeroType == KHeroObjectType.hotPlayer) { entity.Job = (KJob)hero.wNpcIDOrJob; } entity.DispatchEvent(ControllerCommand.SET_DESTINATION, destination, (int)KForceMoveType.fmtInvalid); entity.DispatchEvent(ControllerCommand.CHANGE_NAME, Name); entity.DispatchEvent(ControllerCommand.LOAD_RES); entity.DispatchEvent(ControllerCommand.LOAD_NAME_LABEL, Name); if (Title.Length > 0) { entity.DispatchEvent(ControllerCommand.CHANGE_TITLE, Title); } entity.EquipIDs = hero.equipIDs; if (entity.property.isDeadTemp) { entity.property.isDeadTemp = true; entity.Action.IsBeDead(); } else if (heroSetting.HeroType == KHeroObjectType.hotMonster && hero.bNewHero != 0) { entity.ActiveAction = new ActionMousterOut(entity); } }