示例#1
0
 private void OnTrapAttack(int trapKid)
 {
     TrapData data = TrapDataManager.Instance.GetData(trapKid) as TrapData;
     AttackContext context = new AttackContext();
     context.Side = Side.Neutral;
     context.Attack = data.Attack;
     context.Critical = 0;
     battleProxy.DoAttackMonster(this, context);
     Script.Hit(true);
 }
示例#2
0
        public void AttackMonster(Dictionary<AnimatorParamKey, string> paramDic)
		{
			Dictionary<string, Monster>.Enumerator enumerator = monsterDic.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Monster monster = enumerator.Current.Value;
				bool inArea = JudgeInArea(hero.Script.transform, monster.Script.transform, paramDic);
				if (inArea)
				{
                    AttackContext context = new AttackContext();
                    context.Side = Side.Hero;
                    context.Attack = (int)hero.Info.GetAttribute(BattleAttribute.Attack);
                    context.Critical = (int)hero.Info.GetAttribute(BattleAttribute.Critical);

                    DoAttackMonster(monster, context);
				}
			}
		}
示例#3
0
        public void AttackHero(Monster monster, Dictionary<AnimatorParamKey, string> paramDic)
		{
			AttackContext ac = new AttackContext();
			ac.Side = Side.Monster;
            ac.Attack = (int)monster.Info.GetAttribute(BattleAttribute.Attack);
            ac.Critical = (int)monster.Info.GetAttribute(BattleAttribute.Critical);

			if (monster.Data.AttackType == AttackType.Range)
			{
				Bullet bullet = Bullet.Create(monster.Data.BulletKid);
				bullet.AttackContext = ac;
				bullet.Start(monster.Script.EmitTransform);
			}
			else if (monster.Data.AttackType == AttackType.Melee)
			{
				bool inArea = JudgeInArea(hero.Script.transform, monster.Script.transform, paramDic);
				if (inArea)
				{
					DoAttackHero(ac);
				}
			}
		}
示例#4
0
		public void DoAttackHero(AttackContext attackContext)
		{
			if (hero.Info.IsConverting) return;

			AttackResult result = hero.Info.HurtBy(attackContext);
			if (hero.Info.HP > 0)
			{
				hero.Hit();
			}
			else
			{
				hero.Die();
			}

			DispatchNotification(NotificationEnum.BATTLE_UI_UPDATE_HP, result);
		}
示例#5
0
 public void DoAttackMonster(Monster monster, AttackContext attackContext)
 {
     if (!monster.Info.IsAlive)
     {
         return;
     }
     AttackResult result = monster.Info.HurtBy(attackContext);
     NumberItem.Create(monster.WorldPosition, result);
     if (monster.Info.HP > 0)
     {
         monster.Hit();
     }
     else
     {
         monster.Die();
     }
 }
示例#6
0
		public AttackResult HurtBy(AttackContext attackContext)
		{
			float randomValue = UnityEngine.Random.value;
			AttackResult result = new AttackResult();

			float dodge = GetAttribute(BattleAttribute.Dodge) / RandomUtils.RANDOM_BASE;
			if (randomValue <= dodge)
			{
				result.Damage = 0;
				result.IsCritical = false;
				result.IsDodge = true;
//				Debug.Log(string.Format("{0} dodged...", Data.Kid));
				return result;
			}

			float critical = attackContext.Critical / RandomUtils.RANDOM_BASE;
			result.IsCritical = randomValue <= critical;

			int attack = attackContext.Attack;
            int defense = (int)GetAttribute(BattleAttribute.Defense);
			int criticalRatio = result.IsCritical ? 2 : 1;
			result.Damage = -(attack - defense) * criticalRatio;
			AddHP(result.Damage);
//			Debug.Log(string.Format("{0} was attacked. Damage = {1}", Data.Kid, result.damage));
//			Debug.Log(string.Format("{0}'s HP: {1}", Data.Kid, hp));
			return result;
		}