public void Init() { gameManager = GameManager.Instance; cameraControl = gameManager.CameraControl; gameObject.tag = "Unit"; gameObject.layer = LayerMask.NameToLayer("Units"); CapsuleCollider collision = gameObject.AddComponent <CapsuleCollider>(); collision.radius = 0.1f; collision.height = 1.8f; collision.center = new Vector3(0.0f, 1.0f, 0.0f); animator = GetComponent <Animator>(); unitMover = gameObject.AddComponent <UnitMover>(); unitMover.Init(); unitAttack = gameObject.AddComponent <UnitAttack>(); unitAttack.Init(); TeamName = teamName; hitPoint = maxHits; SkeletonConfig skeletonConfig = gameObject.AddComponent <SkeletonConfigCombot>(); if (skeletonConfig) { skeletonControl = skeletonConfig.Init(); } if (startAsPlayer) { gameManager.ActiveUnit = this; } if (addAI) { aiControl = gameObject.AddComponent <AIController>(); } InventoryObject.PlayerEntry playerData = gameManager.inventory.GetPlayerEntry(unitName); if (playerData == null) { Debug.Log("No PlayerData Found, Adding It"); playerData = new InventoryObject.PlayerEntry(); playerData.name = unitName; playerData.primaryWeapon = "AssaultRifle"; playerData.primaryMagazines = 2; gameManager.inventory.AddPlayerEntry(playerData); } AddWeapon(playerData.primaryWeapon, playerData.primaryMagazines); AddWeapon(playerData.secondaryWeapon, playerData.secondaryMagazines); }
public static IEnumerator <AbilityDeliveryTarget> Deliver(AbilityExecutionContext context, TargetWrapper targetWrapper) { UnitEntityData target = targetWrapper.Unit; if (target == null) { UberDebug.LogError("Target unit is missing"); yield break; } UnitEntityData caster = context.Caster; if (caster.GetThreatHand() == null) { UberDebug.LogError("Invalid caster's weapon"); yield break; } UnitMovementAgent agentASP = caster.View.AgentASP; caster.View.StopMoving(); agentASP.IsCharging = true; agentASP.ForcePath(new ForcedPath(new List <Vector3> { caster.Position, target.Position })); caster.Descriptor.State.IsCharging = true; caster.Descriptor.AddBuff(BlueprintRoot.Instance.SystemMechanics.ChargeBuff, context, 1.Rounds().Seconds); UnitAttack unitAttack = new UnitAttack(target); unitAttack.Init(caster); float timeSinceStart = 0f; while (unitAttack.ShouldUnitApproach) { timeSinceStart += Game.Instance.TimeController.GameDeltaTime; if (timeSinceStart > 6f) { UberDebug.Log("Charge: timeSinceStart > 6f"); yield break; } else if (caster.GetThreatHand() == null) { UberDebug.Log("Charge: caster.GetThreatHand() == null"); yield break; } else if (!caster.Descriptor.State.CanMove) { UberDebug.Log("Charge: !caster.Descriptor.State.CanMove"); yield break; } else if (!(bool)agentASP) { UberDebug.Log("Charge: !(bool)caster.View.AgentASP"); yield break; } else if (!agentASP.IsReallyMoving) { agentASP.ForcePath(new ForcedPath(new List <Vector3> { caster.Position, target.Position })); if (!agentASP.IsReallyMoving) { UberDebug.Log("Charge: !caster.View.AgentASP.IsReallyMoving"); yield break; } } agentASP.MaxSpeedOverride = Math.Max(agentASP.MaxSpeedOverride ?? 0f, caster.CombatSpeedMps * 2f); yield return(null); } caster.View.StopMoving(); unitAttack.IgnoreCooldown(null); unitAttack.IsCharge = true; caster.Commands.AddToQueueFirst(unitAttack); }
public override IEnumerator <AbilityDeliveryTarget> Deliver(AbilityExecutionContext context, TargetWrapper target) { if (target.Unit == null) { UberDebug.LogError("Target unit is missing", Array.Empty <object>()); yield break; } UnitAttack cmd = new UnitAttack(target.Unit) { IsSingleAttack = true }; cmd.Init(context.Caster); cmd.Start(); AttackHandInfo attackHandInfo = cmd.AllAttacks.FirstOrDefault <AttackHandInfo>(); ItemEntityWeapon weapon = (attackHandInfo != null) ? attackHandInfo.Weapon : null; if (weapon == null) { UberDebug.LogError("Has no weapon for attack", Array.Empty <object>()); cmd.Interrupt(); yield break; } bool hitHandled = false; bool isMelee = weapon.Blueprint.IsMelee; for (; ;) { if (cmd.IsFinished) { RuleAttackWithWeapon lastAttackRule = cmd.LastAttackRule; if (((lastAttackRule != null) ? lastAttackRule.Projectile : null) == null || cmd.LastAttackRule.Projectile.IsHit || cmd.LastAttackRule.Projectile.Cleared || cmd.LastAttackRule.Projectile.Destroyed) { break; } } bool wasActed = cmd.IsActed; if (!cmd.IsFinished) { cmd.Tick(); } RuleAttackWithWeapon lastAttackRule2 = cmd.LastAttackRule; if (!wasActed && cmd.IsActed && isMelee) { hitHandled = true; if (lastAttackRule2.AttackRoll.IsHit) { yield return(new AbilityDeliveryTarget(target)); } } yield return(null); } if (!hitHandled && !isMelee) { RuleAttackWithWeapon lastAttackRule3 = cmd.LastAttackRule; bool?flag3 = (lastAttackRule3 != null) ? new bool?(lastAttackRule3.AttackRoll.IsHit) : null; if (flag3 != null && flag3.Value) { yield return(new AbilityDeliveryTarget(target)); } } yield break; }