private void OnTriggerEnter(Collider other) { try { SetDustcloud(true); AttackValue currentCollision = other.gameObject.GetComponent <AttackValue>(); if (currentCollision.attacking) { attackingArmyValue -= currentCollision.attackValue != 0 ? currentCollision.attackValue : 1; if (!attackersWon) { currentCollision.gameObject.SetActive(false); } } else { defendingArmyValue -= currentCollision.attackValue != 0 ? currentCollision.attackValue : 1; if (attackersWon) { currentCollision.gameObject.SetActive(false); } } CheckIfBattleIsOver(); } catch (System.NullReferenceException) { } }
private void UpdateAttackBar() { if (_attackBar) { _attackBar.Text.text = AttackValue.ToString("N0"); } }
public SyncUnitInfo(Unit unit) { UnitNode node = unit.Node; baseInfo.model = unit.Model; baseInfo.name = unit.Name; baseInfo.maxHp = unit.MaxHpBase; AttackAct attack = unit.AttackSkill as AttackAct; if (attack != null) { baseInfo.attackSkill = new AttackInfo(); baseInfo.attackSkill.cd = attack.coolDownBase; baseInfo.attackSkill.type = AttackValue.TypeToName(attack.AttackType); baseInfo.attackSkill.value = attack.AttackValueBase; baseInfo.attackSkill.range = attack.CastRange; baseInfo.attackSkill.horizontal = attack.CastHorizontal; List <int> castAnimations = attack.castAnimations; baseInfo.attackSkill.animations = new string[castAnimations.Count]; for (int i = 0; i < castAnimations.Count; ++i) { baseInfo.attackSkill.animations[i] = ModelNode.IdToName(castAnimations[i]); } baseInfo.attackSkill.projectile = attack.ProjectileTemplate.Model; } position = node.position; flippedX = node.flippedX; hp = unit.Hp; force = unit.force.Force; baseInfo.move = unit.MoveSpeedBase; baseInfo.revivable = unit.Revivable; baseInfo.isfixed = unit.Fixed; }
private void UsePower() { AttackValue attack = attackValues.CurrentAttack; if (attack == AttackValue.Bite) { if (stanima.IsThereEnough(attackValues.StanimaUsageBite)) { SoundManager.Instance.PlaySingle("Bite1"); stanima.ReduceStanima(attackValues.StanimaUsageBite); Instantiate(bite, transform.position, transform.rotation); Debug.Log("Bite Attack Occured"); } } else if (attack == AttackValue.Cough) { if (stanima.IsThereEnough(attackValues.StanimaUsageCough)) { SoundManager.Instance.PlaySingle("Cough1"); stanima.ReduceStanima(attackValues.StanimaUsageCough); Instantiate(cough, transform.position, transform.rotation); Debug.Log("Cough Attack Occured"); } } else if (attack == AttackValue.Slap) { if (stanima.IsThereEnough(attackValues.StanimaUsageSlap)) { SoundManager.Instance.PlaySingle("Slap1"); stanima.ReduceStanima(attackValues.StanimaUsageSlap); Instantiate(slap, transform.position, transform.rotation); Debug.Log("Slap Attack Occured"); } } else if (attack == AttackValue.Sneeze) { if (stanima.IsThereEnough(attackValues.StanimaUsageSneeze)) { SoundManager.Instance.PlaySingle("Sneeze1"); stanima.ReduceStanima(attackValues.StanimaUsageSneeze); Instantiate(sneeze, transform.position, transform.rotation); Debug.Log("Sneeze Attack Occured"); } } else if (attack == AttackValue.Vomit) { if (stanima.IsThereEnough(attackValues.StanimaUsageVomit)) { SoundManager.Instance.PlaySingle("Vomit1"); stanima.ReduceStanima(attackValues.StanimaUsageVomit); Instantiate(vomit, transform.position, transform.rotation); Debug.Log("Vomit Attack Occured"); } } }
public AttackData(AttackValue value, List <AttackBuff> buff = null) { m_attackValue = value; if (buff != null) { m_attackBuffs = new List <AttackBuff>(buff); } else { m_attackBuffs = new List <AttackBuff>(); } }
public override string ToString() { string weaponString = base.ToString() + ", "; weaponString += NumberHands.ToString() + ", "; weaponString += AttackValue.ToString() + ", "; weaponString += AttackModifier.ToString() + ", "; weaponString += DamageEffect.ToString(); foreach (string s in AllowableClasses) { weaponString += ", " + s; } return(weaponString); }
public override void OnUnitAttackTarget(AttackData pAttack, Unit pTarget) { Unit o = m_owner; if (!pTarget || o == null) { return; } UnitNode td = pTarget.Node; float fDis; World w = o.World; var units = w.Units; foreach (Unit pUnit in units.Keys) { if (pUnit == pTarget) { continue; } UnitNode pDraw = pUnit.Node; if (pUnit.Ghost) { continue; } fDis = Mathf.Max(0.0f, Vector2.Distance(pDraw.position, td.position) - pDraw.HalfOfWidth); if (fDis <= m_fFarRange && o.force.CanEffect(pUnit.force, m_effectiveTypeFlags)) { AttackData ad = pAttack.Clone(); AttackValue av = ad.attackValue; if (fDis <= m_fNearRange) { av.x = m_oExNearDamage.GetValue(av.v); } else { av.x = m_oExFarDamage.GetValue(av.v); } pUnit.Damaged(ad, o, m_dwTriggerMask); } } }
public override string ToString() { string weapString = base.ToString() + ", "; weapString += NumberHands.ToString() + ", "; weapString += AttackValue.ToString() + ", "; weapString += AttackModifier.ToString() + ", "; weapString += DamageValue.ToString() + ", "; weapString += DamageModifier.ToString() + ", "; foreach (Type t in allowableClasses) { weapString += ", " + t.Name; } return(base.ToString()); }
private void SwitchPower(AttackValue attack) { attackValues.CurrentAttack = attack; if (attack == AttackValue.Bite) { attackImage.SetBool("Bite", true); attackImage.SetBool("Cough", false); attackImage.SetBool("Sneeze", false); attackImage.SetBool("Slap", false); attackImage.SetBool("Vomit", false); } else if (attack == AttackValue.Cough) { attackImage.SetBool("Bite", false); attackImage.SetBool("Cough", true); attackImage.SetBool("Sneeze", false); attackImage.SetBool("Slap", false); attackImage.SetBool("Vomit", false); } else if (attack == AttackValue.Sneeze) { attackImage.SetBool("Bite", false); attackImage.SetBool("Cough", false); attackImage.SetBool("Sneeze", true); attackImage.SetBool("Slap", false); attackImage.SetBool("Vomit", false); } else if (attack == AttackValue.Slap) { attackImage.SetBool("Bite", false); attackImage.SetBool("Cough", false); attackImage.SetBool("Sneeze", false); attackImage.SetBool("Slap", true); attackImage.SetBool("Vomit", false); } else if (attack == AttackValue.Vomit) { attackImage.SetBool("Bite", false); attackImage.SetBool("Cough", false); attackImage.SetBool("Sneeze", false); attackImage.SetBool("Slap", false); attackImage.SetBool("Vomit", true); } }
/// <summary> /// Server发起 /// </summary> /// <param name="syncInfo"></param> /// <param name="playerId"></param> public Unit CreateUnit(SyncUnitInfo syncInfo, int playerId = 0) { localClient.ServerAddSyncAction(new SyncCreateUnit(syncInfo, playerId)); GamePlayerController player; GameManager.AllPlayers.TryGetValue(playerId, out player); GameObject obj = GameObjectPool.instance.Instantiate(unitPrefab); UnitNode node = obj.GetComponent <UnitNode>(); Unit unit = obj.GetComponent <Unit>(); ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model); // high time cost ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node); unit.m_id = syncInfo.id; node.m_id = syncInfo.id; AddUnit(unit); unit.m_model = syncInfo.baseInfo.model; if (isServer) { unit.AI = UnitAI.instance; } unit.Name = syncInfo.baseInfo.name; unit.InitHp(syncInfo.hp, (float)syncInfo.baseInfo.maxHp); if (syncInfo.baseInfo.attackSkill.valid) { AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange); atk.CastRange = (float)syncInfo.baseInfo.attackSkill.range; atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal; foreach (string ani in syncInfo.baseInfo.attackSkill.animations) { atk.AddCastAnimation(ModelNode.NameToId(ani)); } atk.ProjectileTemplate = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile); unit.AddActiveSkill(atk); } node.position = syncInfo.position; node.SetFlippedX(syncInfo.flippedX); unit.force.Force = syncInfo.force; unit.MoveSpeedBase = (float)syncInfo.baseInfo.move; unit.Revivable = syncInfo.baseInfo.revivable; unit.Fixed = syncInfo.baseInfo.isfixed; unit.level.MaxLevel = 100; unit.level.Level = 10; if (player != null) { // 玩家单位 Debug.LogFormat("CreateUnit, unitId({0}) <-> playerId({1}).", unit.Id, player.playerId); if (player == localClient) { Debug.LogFormat("That's Me, {0}.", unit.Name); } // TEST !!!! unit.InitHp(5000, 5000); unit.AttackSkill.coolDownBase = 2.0f; unit.AttackSkill.coolDownSpeedCoeff = 2; unit.CriticalRateBase = 0.2f; unit.CriticalDamageBase = 20.0f; SplashPas splash = new SplashPas("SplashAttack", 0.5f, new Coeff(0.75f, 0), 1f, new Coeff(0.25f, 0)); unit.AddPassiveSkill(splash); if (player == localClient) { BattleWorldUI.Current.portraitGroup.AddPortrait(unit); } } node.SetFrame(ModelNode.kFrameDefault); CreateUnitHUD(unit); return(unit); }
public AttackData() { m_attackValue = new AttackValue(AttackValue.Type.kPhysical, 0); m_attackBuffs = new List <AttackBuff>(); }
new public void FromXML(string xml) { this.currentAttacks = new List<AttackValue>(); this.currentPercentages = new Dictionary<string, int>(); Match m = regex.Match(xml); if (m.Success) { string attacks = m.Groups[1].Value; foreach (Match m2 in attackregex.Matches(attacks)) { AttackValue av; string capabilityName = String.Empty; int attackStartTime = 0; int attackTimeWindow = 0; string targetObjectId = String.Empty; string attackingObjectId = String.Empty; int percentageApplied = 0; bool isSelfdefense = false; string errMsg = String.Empty; try { capabilityName = m2.Groups[1].Value; attackStartTime = Int32.Parse(m2.Groups[2].Value); attackTimeWindow = Int32.Parse(m2.Groups[3].Value); targetObjectId = m2.Groups[4].Value; attackingObjectId = m2.Groups[5].Value; percentageApplied = Int32.Parse(m2.Groups[6].Value); isSelfdefense = Boolean.Parse(m2.Groups[7].Value); } catch (Exception ex) { Console.WriteLine("Error in AttackCollectionValue.FromXML; " + ex.Message); } av = new AttackValue(attackStartTime, attackTimeWindow, targetObjectId, attackingObjectId, capabilityName, percentageApplied, isSelfdefense); this.AddAttack(av, out errMsg); if (errMsg != string.Empty) { Console.WriteLine("Error in AttackCollectionValue.AddAttack: " + errMsg); } } } }
public bool RemoveAttack(AttackValue attack) { bool returnValue = true; int indexToRemove = -1; int counter = 0; foreach (AttackValue av in currentAttacks) { if (av == attack) { indexToRemove = counter; break; } counter++; } if (indexToRemove >= 0) { if (currentPercentages.ContainsKey(attack.capabilityName)) { currentPercentages[attack.capabilityName] -= attack.percentageApplied; } currentAttacks.RemoveAt(indexToRemove); } else { returnValue = false; } return returnValue; }
/// <summary> /// Adds an attack to this collection. /// </summary> /// <param name="attack">The attack object to add to this collection.</param> /// <param name="errorMessage">If this has anything besides String.Empty upon return, then the attack was not added in the FULL /// capacity of the original request. If this function returned TRUE, then it was added partially. If it was returned FALSE, /// then this attack was not added at all.</param> /// <returns></returns> public bool AddAttack(AttackValue attack, out String errorMessage) { bool returnValue = true; errorMessage = String.Empty; int possiblePercentageToApply = MaximumPercentage; foreach (AttackValue av in currentAttacks) { if (av.capabilityName != attack.capabilityName) continue; possiblePercentageToApply -= av.percentageApplied; } if (possiblePercentageToApply < attack.percentageApplied) { if (possiblePercentageToApply > 0) { errorMessage = "Applying " + possiblePercentageToApply.ToString() + "% instead of " + attack.percentageApplied.ToString() + "%, as that's all available"; } else {// percentage applied is 0 or less errorMessage = "There is no more available percentage to apply for this capability. Try again later."; returnValue = false; return returnValue; } } attack.percentageApplied = Math.Min(attack.percentageApplied, possiblePercentageToApply); currentAttacks.Add(attack); if (!currentPercentages.ContainsKey(attack.capabilityName)) { currentPercentages.Add(attack.capabilityName, 0); } currentPercentages[attack.capabilityName] += attack.percentageApplied; return returnValue; }
public KingCannibalFlowerAttack(Enemy parent, LayerMask targetLayer, float normalProbability, float specialProbability, AttackValue vineStingValue, AttackValue vineScratchValue, AttackValueRadius biteValue, AttackValueRadius vineValue, AttackValueRadius needleValue, List <Collider2D> vines, List <Collider2D> needles) : base(parent) { //set own to kcf kcf = (KingCannibalFlower)Parent; //set targetLayer and add vines collider and probability this.targetLayer = targetLayer; this.vines.AddRange(vines); this.needles.AddRange(needles); this.normalProbability = normalProbability; this.specialProbability = specialProbability; //instantiation all attack and add to attacks attacks.Add(this.vineSting = new AttackSet(vineStingValue, new BasicAttack(vineStingValue.CD, VineStingAttacking))); attacks.Add(this.vineScratch = new AttackSet(vineScratchValue, new BasicAttack(vineScratchValue.CD, VineScratchAttacking))); attacks.Add(this.bite = new AttackSet(biteValue, new CircleAreaAttack(biteValue.CD, biteValue.DetectRadius, targetLayer))); attacks.Add(this.vine = new AttackSet(vineValue, new CircleAreaAttack(vineValue.CD, vineValue.DetectRadius, targetLayer, VineAttacking))); attacks.Add(this.needle = new AttackSet(needleValue, new CircleAreaAttack(needleValue.CD, needleValue.DetectRadius, targetLayer, NeedleAttacking))); //add attack to one they belong to specialAttacks.Add(vineScratch); specialAttacks.Add(vineSting); normalAttacks.Add(bite); normalAttacks.Add(needle); normalAttacks.Add(vine); //register the OnAnimationFinished on Parent for AnimFinished kcf.OnAnimationFinished += AnimFinished; //try to find the player on the scene GalaxySeeker.Physics2D.OverlapCircle(Parent.tf.position, Mathf.Infinity, targetLayer, ref targetTransform); if (targetTransform) { target = targetTransform.GetComponent <Character> ( ); } }
public Tank CreateTank(TankSyncInfo syncInfo, int playerId = 0) { GamePlayerController player; GameManager.AllPlayers.TryGetValue(playerId, out player); GameObject obj = GameObjectPool.instance.Instantiate(unitPrefab); TankNode node = obj.GetComponent <TankNode>(); Tank unit = obj.GetComponent <Tank>(); //TankController ctrl = obj.GetComponent<TankController>(); ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model); // high time cost ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node); unit.m_id = syncInfo.id; node.m_id = syncInfo.id; AddUnit(unit); //unit.m_client = player; unit.m_model = syncInfo.baseInfo.model; if (localClient.isServer) { unit.AI = UnitAI.instance; } unit.Name = syncInfo.baseInfo.name; unit.MaxHpBase = (float)syncInfo.baseInfo.maxHp; if (syncInfo.baseInfo.attackSkill.valid) { AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange); atk.CastRange = (float)syncInfo.baseInfo.attackSkill.range; atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal; foreach (var ani in syncInfo.baseInfo.attackSkill.animations) { atk.AddCastAnimation(ModelNode.NameToId(ani)); } atk.ProjectileTemplate = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile); atk.ProjectileTemplate.fire = "Straight"; unit.AddActiveSkill(atk); } node.position = syncInfo.position; node.rotation = syncInfo.rotation; unit.Hp = syncInfo.hp; unit.force.Force = syncInfo.force; unit.MoveSpeedBase = (float)syncInfo.baseInfo.move; unit.Revivable = syncInfo.baseInfo.revivable; unit.Fixed = syncInfo.baseInfo.isfixed; for (int i = 0; i < syncInfo.guns.Count; ++i) { unit.AddGun(i); unit.SetGunPosition(i, syncInfo.guns[i].position); unit.SetGunRotation(i, syncInfo.guns[i].rotation); //syncInfo.guns[i].rotateSpeed; } return(unit); }
public override void Hitted(AttackValue atkv) { this.hp -= atkv.attack; hited = true; //被击中 }
public AttackAct(string name, float coolDown, AttackValue attackValue, float attackValueRandomRange = 0.15f) : base(name, coolDown, CommandTarget.Type.kUnitTarget, ForceEffective.kEnemy) { m_attackValue = attackValue; m_attackValueRandomRange = new Value(attackValueRandomRange); }