public void DispatchDamageEventHandler(VCharacter vCharacter) { if (OnDamageEventHandler != null) { OnDamageEventHandler(vCharacter); } }
public override void Awake() { base.Awake(); if (vCharacter == null) { vCharacter = GetComponent <VCharacter>(); } }
/// <summary> /// 行动中武将移除 /// </summary> /// <param name="vCharacter">V character.</param> public void RemoveDynamicCharacter(VCharacter vCharacter) { dynamicCharacters.Remove(vCharacter); if (!HasDynamicCharacter()) { this.ActionEnd(); } }
/// <summary> /// 行动中武将挂起 /// </summary> /// <param name="vCharacter">V character.</param> public void AddDynamicCharacter(VCharacter vCharacter) { if (dynamicCharacters.Contains(vCharacter)) { return; } //Debug.LogError("行动中武将 " + vCharacter.ViewModel.Action.Value + ","+vCharacter.ViewModel.Name.Value + ","+vCharacter.ViewModel.Belong.Value); dynamicCharacters.Add(vCharacter); }
public override void OnClickTile(int index) { App.Model.Master.MBaseMap topMapMaster = BaseMapCacher.Instance.Get(mBaseMap.MapId); Vector2 coordinate = topMapMaster.GetCoordinateFromIndex(index); List <VCharacter> vCharacters = vBaseMap.Characters; VCharacter vCharacter = vBaseMap.Characters.Find(_ => _.ViewModel.CoordinateX.Value == coordinate.x && _.ViewModel.CoordinateY.Value == coordinate.y); if (vCharacter != null) { App.Util.LSharp.LSharpScript.Instance.Analysis(new List <string> { string.Format("Call.characterclick_{0}();", vCharacter.ViewModel.Id.Value) }); } }
public void OnDamage(VCharacter vCharacter) { MCharacter mCharacter = this.GetCharacterModel(vCharacter); MCharacter targetModel = vCharacter.ViewModel.Target.Value; VCharacter target = this.GetCharacterView(targetModel); List <VCharacter> characters = this.charactersManager.GetTargetCharacters(vCharacter, target, vCharacter.ViewModel.CurrentSkill.Value.Master); App.View.VTile tile = mapSearch.GetTile(mCharacter.CoordinateX, mCharacter.CoordinateY); foreach (VCharacter child in characters) { MCharacter childModel = this.GetCharacterModel(child); bool hit = calculateManager.AttackHitrate(mCharacter, childModel); if (!hit) { child.SendMessage(CharacterEvent.OnBlock.ToString()); continue; } App.Model.Battle.MDamageParam arg = new App.Model.Battle.MDamageParam(-this.calculateManager.Hert(mCharacter, childModel, tile)); child.SendMessage(CharacterEvent.OnDamage.ToString(), arg); if (child.ViewModel.CharacterId.Value != targetModel.CharacterId) { continue; } if (mCharacter.CurrentSkill.Master.effect.enemy.time == App.Model.Master.SkillEffectBegin.enemy_hert) { if (mCharacter.CurrentSkill.Master.effect.special == App.Model.Master.SkillEffectSpecial.vampire) { App.Model.Master.MStrategy strategy = App.Util.Cacher.StrategyCacher.Instance.Get(mCharacter.CurrentSkill.Master.effect.enemy.strategys[0]); VCharacter currentCharacter = this.GetCharacterView(mCharacter); int addHp = -UnityEngine.Mathf.FloorToInt(arg.value * strategy.hert * 0.01f); App.Model.Battle.MDamageParam arg2 = new App.Model.Battle.MDamageParam(addHp); currentCharacter.SendMessage(CharacterEvent.OnHealWithoutAction.ToString(), arg2); } } else if (mCharacter.CurrentSkill.Master.effect.enemy.time == App.Model.Master.SkillEffectBegin.attack_end) { if (mCharacter.CurrentSkill.Master.effect.special == App.Model.Master.SkillEffectSpecial.status) { int specialValue = mCharacter.CurrentSkill.Master.effect.special_value; if (specialValue > 0 && UnityEngine.Random.Range(0, 50) > specialValue) { continue; } childModel.attackEndEffects.Add(mCharacter.CurrentSkill.Master.effect.enemy); } } } }
public void OnHeal(VCharacter vCharacter) { //UnityEngine.Debug.LogError("OnHeal"); MCharacter mCharacter = this.GetCharacterModel(vCharacter); MCharacter targetModel = vCharacter.ViewModel.Target.Value; VCharacter target = this.GetCharacterView(targetModel); List <VCharacter> characters = this.charactersManager.GetTargetCharacters(vCharacter, target, vCharacter.ViewModel.CurrentSkill.Value.Master); App.View.VTile tile = mapSearch.GetTile(mCharacter.CoordinateX, mCharacter.CoordinateY); foreach (VCharacter child in characters) { App.Model.Battle.MDamageParam arg = new App.Model.Battle.MDamageParam(this.calculateManager.Heal(mCharacter, this.GetCharacterModel(child), tile)); child.SendMessage(CharacterEvent.OnHeal.ToString(), arg); } }
private void CharactersChanged(App.Model.MCharacter[] oldvalue, App.Model.MCharacter[] newvalue) { if (newvalue == null || newvalue.Length == 0) { return; } foreach (App.Model.MCharacter mCharacter in newvalue) { VCharacter vCharacter = vCharacters.Find(_ => _.ViewModel.Id.Value == mCharacter.Id); if (vCharacter == null) { //新建武将 GameObject obj = this.Controller.ScrollViewSetChild(characterLayer.transform, characterPrefab, mCharacter); obj.name = string.Format("Character_{0}_{1}", mCharacter.Belong.ToString(), mCharacter.CharacterId.ToString()); int i = mCharacter.CoordinateY * mapWidth + mCharacter.CoordinateX; VTile vTile = tileUnits[i]; obj.transform.eulerAngles = new Vector3(-30f, 0f, 0f); obj.transform.localPosition = vTile.transform.localPosition; obj.transform.localScale = new Vector3(0.6f, 0.6f, 1f); mCharacter.X = obj.transform.localPosition.x; mCharacter.Y = obj.transform.localPosition.y; mCharacter.Action = App.Model.ActionType.idle; obj.GetComponent <VCharacter>().UpdateView(); } else { vCharacters.Remove(vCharacter); //更新武将 } } if (vCharacters.Count > 0) { //删除多余武将 } vCharacters = characterLayer.GetComponentsInChildren <VCharacter>(true).ToList(); }
/// <summary> /// 获取攻击到的所有敌人 /// </summary> /// <returns>The damage characters.</returns> /// <param name="vCharacter">攻击方</param> /// <param name="targetView">攻击目标</param> /// <param name="skill">Skill.</param> public List <VCharacter> GetTargetCharacters(VCharacter vCharacter, VCharacter targetView, App.Model.Master.MSkill skill) { List <VCharacter> result = new List <VCharacter>() { targetView }; if (skill.radius_type == RadiusType.point) { return(result); } List <VCharacter> characters; if (System.Array.Exists(skill.types, s => s == SkillType.heal)) { characters = vBaseMap.Characters.FindAll(c => c.ViewModel.Hp.Value > 0 && this.IsSameBelong(c.ViewModel.Belong.Value, vCharacter.ViewModel.Belong.Value) && !this.IsSameCharacter(targetView, c)); } else/* if (System.Array.Exists(skill.types, s => s == SkillType.attack))*/ { characters = vBaseMap.Characters.FindAll(c => c.ViewModel.Hp.Value > 0 && this.IsSameBelong(c.ViewModel.Belong.Value, targetView.ViewModel.Belong.Value) && !this.IsSameCharacter(targetView, c)); } VTile targetTile; if (skill.effect.special == App.Model.Master.SkillEffectSpecial.attack_all_near) { targetTile = cBattlefield.mapSearch.GetTile(vCharacter.ViewModel.CoordinateX.Value, vCharacter.ViewModel.CoordinateY.Value); } else { targetTile = cBattlefield.mapSearch.GetTile(targetView.ViewModel.CoordinateX.Value, targetView.ViewModel.CoordinateY.Value); } if (skill.radius_type == RadiusType.range) { foreach (VCharacter child in characters) { VTile tile = cBattlefield.mapSearch.GetTile(child.ViewModel.CoordinateX.Value, child.ViewModel.CoordinateY.Value); if (targetTile.Index != tile.Index && cBattlefield.mapSearch.GetDistance(targetTile, tile) <= skill.radius) { result.Add(child); } } bool quantity_plus = skill.effect.special == App.Model.Master.SkillEffectSpecial.quantity_plus; if (quantity_plus) { List <VCharacter> resultPlus = new List <VCharacter>(); while (result.Count > 1 && resultPlus.Count < skill.effect.special_value) { int index = Random.Range(1, result.Count - 1); VCharacter plusView = result[index]; resultPlus.Add(plusView); result.RemoveAt(index); } resultPlus.Add(targetView); return(resultPlus); } } else if (skill.radius_type == RadiusType.direction) { VTile tile = cBattlefield.mapSearch.GetTile(vCharacter.ViewModel.CoordinateX.Value, vCharacter.ViewModel.CoordinateY.Value); int distance = cBattlefield.mapSearch.GetDistance(targetTile, tile); if (distance > 1) { return(result); } var direction = cBattlefield.mapSearch.GetDirection(tile, targetTile); var radius = skill.radius; while (radius-- > 0) { tile = cBattlefield.mapSearch.GetTile(targetTile, direction); VCharacter child = GetCharacter(tile.Index, characters); if (child == null) { break; } result.Add(child); targetTile = tile; } } return(result); }
public bool IsSameCharacter(VCharacter character1, VCharacter character2) { return(character1.ViewModel.Belong.Value == character2.ViewModel.Belong.Value && character1.ViewModel.Id.Value == character2.ViewModel.Id.Value); }