protected void Awake() { GameManager.Instance.SetPlayer(this); rigid = GetComponent <Rigidbody2D>(); shadow = transform.GetChild(0).gameObject; status = StatusManager.Instance.GetStatus(UnitName); status.hp = 100f; status.stamina = 100f; state = UnitState.Idle; ChildSetting(transform); //하위 컴포넌트 초기화 { animator = GetComponent <UnitAnimator>(); attack = GetComponent <UnitAttack>(); movement = GetComponent <UnitMovement>(); colliderctrl = GetComponent <UnitColliderController>(); animator.ConnectUnit(this); attack.ConnectUnit(this); movement.ConnectUnit(this); colliderctrl.ConnectUnit(this); } shadow.transform.parent = null; StartCoroutine(Shadow()); }
static bool Prefix(UnitAttack __instance, AttackHandInfo attack) { var combatManeuver = Rulebook.Trigger(new RuleCheckCombatManeuverReplaceAttack(__instance.Executor, __instance.Target, attack)).Result; if (combatManeuver == CombatManeuver.None) { return(true); } var lastAttackRule = new RuleAttackWithWeapon(__instance.Executor, __instance.Target, attack.Weapon, attack.AttackBonusPenalty) { IsRend = __instance.IsRend(__instance.PlannedAttack), IsFirstAttack = (attack.AttackNumber == 0), IsFullAttack = __instance.IsFullAttack, IsCharge = __instance.IsCharge, AttackNumber = attack.AttackNumber, AttacksCount = ((List <AttackHandInfo>)unitattack_get_m_AllAttacks(__instance)).Count }; unitattack_set_LastAttackRule(__instance, lastAttackRule); attack.Target = __instance.Target; attack.IsHit = __instance.Executor.TriggerAttackReplacementCombatManeuver(__instance.Target, attack.Weapon, attack.AttackBonusPenalty, combatManeuver); return(false); }
// Use this for initialization void Awake() { _unitCtrl = GetComponent <UnitController>(); _unitMove = GetComponent<UnitMove>(); _unitAttack = GetComponent<UnitAttack>(); _unitSpine = GetComponentInChildren<UnitSpine>() ? GetComponentInChildren<UnitSpine>() : null; }
// Use this for initialization public void Init(Vector3 start, Vector3 end, UnitAttack attack, float altitude = 0.0f) { transform.position = start; this.attack = attack; move = GetComponent <UnitMove> (); move.Init(end, altitude); }
void Start() { animator = GetComponent <Animator>(); if (isBarricade) { return; } unitAttack = GetComponent <UnitAttack>(); unitMover = GetComponent <UnitMover>(); FindNewEnemy(true); Rigidbody rb = gameObject.AddComponent <Rigidbody>(); rb.mass = 10; rb.constraints = RigidbodyConstraints.FreezeRotation; SetTeamColor(); ragdollControl = GetComponent <RagdollConfig>().Init(); torso = transform.Find("Man:Hips/Man:Torso"); rightHand = torso.Find("Man:RightUpperArm/Man:RightLowerArm/Man:Attach_RightHand"); leftHand = torso.Find("Man:LeftUpperArm/Man:LeftLowerArm/Man:Attach_LeftHand"); if (isWaiting) { rb.isKinematic = true; } }
/// <summary> /// Fires the attack event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _attack_timer_Tick(object sender, object e) { var miliseconds = rand.Next(500 - AttackSpeed, 1000 - AttackSpeed); _timer.Interval = new TimeSpan(0, 0, 0, 0, miliseconds); UnitAttack?.Invoke(this, Attack, UnitType, Team); }
void Start() { unitAttack = GetComponent <UnitAttack>(); unitControl = GetComponent <UnitControl>(); animator = GetComponent <Animator>(); animator.SetFloat("random", Random.value); homePosition = transform.position; }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!unitAttack) { unitAttack = animator.gameObject.GetComponent <UnitAttack>(); } unitAttack.IsAiming = true; }
public void Init() { unitMove = gameObject.GetComponent <UnitMove>(); unitAttack = gameObject.GetComponent <UnitAttack>(); turnManager = FindObjectOfType <TurnManager>(); _Ui = FindObjectOfType <CurrentCharacterInformation>(); TurnManager.AddUnitToGame(gameObject.tag, this); }
protected override void Start() { base.Start(); mInteraction = this.GetComponent <UnitInteraction>(); mMotor = this.GetComponent <UnitMotor>(); mAttack = this.GetComponent <UnitAttack>(); mData = this.GetComponent <UnitData>(); }
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 virtual void StateInit() { gameManager = GameManager.Instance; ai = GetComponent <AIController>(); unitControl = GetComponent <UnitControl>(); unitAttack = GetComponent <UnitAttack>(); unitMover = GetComponent <UnitMover>(); mapControl = gameManager.ActiveMap; }
public void Init() { gameManager = GameManager.instance; gameObject.tag = "Unit"; gameObject.layer = LayerMask.NameToLayer("Units"); animator = GetComponent <Animator>(); unitMover = gameObject.AddComponent <UnitMover>(); unitAttack = gameObject.AddComponent <UnitAttack>(); //navAgent = gameObject.AddComponent<NavMeshAgent>(); TeamName = teamName; AddWeapon(TempPrimaryWeapon); if (!TempSecondaryWeapon.Equals("")) { AddWeapon(TempSecondaryWeapon); } if (!squad && teamName.Equals("Player")) { squad = gameManager.PlayerSquad; } if (!squad) { Debug.Log(transform.name + " has no squad"); } UnitId = squad.AddUnit(this); animator.SetFloat("AnimOffset", (float)UnitId / 4.0f); transform.position = SquadPosition; transform.rotation = squad.transform.rotation; CapsuleCollider collision = gameObject.AddComponent <CapsuleCollider>(); collision.radius = 0.5f; collision.height = 2.0f; collision.center = new Vector3(0.0f, 1.0f, 0.0f); hitPoint = maxHits; RagdollConfig ragdollConfig = gameObject.AddComponent <RagdollConfigCombot>(); if (ragdollConfig) { ragdollControl = ragdollConfig.Init(); } }
private void Start() { unitAttack = this.gameObject.AddComponent <UnitAttack>(); unitAttack.Initialize(this.gameObject); unitProfile = this.gameObject.AddComponent <UnitProfile>(); unitProfile.Initialize(); movement = this.gameObject.AddComponent <Movement>(); movement.Initialize(groundTilemap, collisionTilemap); startingPosition = gameObject.transform.position; }
protected virtual void Awake() { m_unit = GetComponent <Unit>(); Assert.IsNotNull(m_unit); m_tankMovement = GetComponent <UnitMovement>(); Assert.IsNotNull(m_tankMovement); m_tankShooting = GetComponent <UnitAttack>(); Assert.IsNotNull(m_tankShooting); }
public void Init(UnitAttack attack) { if (null == attack) { return; } icon.sprite = attack.info.icon; skillName.text = attack.info.name; mana.text = attack.data.mana.ToString(); cooltime.text = attack.data.cooltime.ToString(); description.text = attack.info.description; }
protected void Init() { tiles = GameObject.FindGameObjectsWithTag("tile"); displayStats = GetComponent <DisplayStats>(); moveRange = displayStats.stats.Movement; halfHeight = GetComponentInChildren <Collider>().bounds.extents.y; if (displayStats == null) { Debug.LogWarning("NO STATS ASSIGNED TO " + this.gameObject.name); } unitAttack = GetComponent <UnitAttack>(); TurnManager.AddUnit(this); }
public void SelectUnit() { //actually select the starting unit for the player CombatPhaseManager.Current.currentUnitSelected.GetComponent <Interactive>().Select(); //turn on the unit portrait if it is not enabled already if (InfoManager.Current.SelectedUnitPortrait.enabled == false) { InfoManager.Current.SelectedUnitPortrait.enabled = true; } //enable the attack script UnitAttack attackScript = CombatPhaseManager.Current.currentUnitSelected.AddComponent <UnitAttack>(); //pass off to UnitAttack to wait and listen for an attack attackScript.FindTarget(); }
public static void SpawnHostileUnit(Vector3 position, BlueprintUnit unit) { var currentMode = Game.Instance.CurrentMode; if (currentMode == GameModeType.Default || currentMode == GameModeType.Pause) { var player = Game.Instance.Player; var target = player.Party.Random <UnitEntityData>(); var executor = Game.Instance.EntityCreator.SpawnUnit(unit, position, Quaternion.LookRotation(target.OrientationDirection), Game.Instance.CurrentScene.MainState); if (!executor.AttackFactions.Contains(Game.Instance.BlueprintRoot.PlayerFaction)) { executor.AttackFactions.Add(Game.Instance.BlueprintRoot.PlayerFaction); } executor.Commands.Run(UnitAttack.CreateAttackCommand(executor, target)); } }
IEnumerator AIUnitAttack(Unit unit) { while (isInAction) { yield return(null); } isInAction = true; //simulate thinking yield return(new WaitForSeconds(1f)); UnitAttack dattack = unit.GetComponent <UnitAttack>(); GameObject unitPos = BoardManager.Instance.GetPositionOfUnit(unit); List <GameObject> attackFields = dattack.GetAttackTiles(unitPos, true, BoardManager.TileType.Attack) .OrderBy(i => Vector3.Distance(i.transform.position, unitPos.transform.position)).ToList(); while (GameController.Instance.State == GameController.GameState.PerformingAction) { yield return(null); } if (attackFields.Count > 0) { //simulate thinking yield return(new WaitForSeconds(1f)); Unit closestEnemy = Unit.UnitsList.Where(i => BoardManager.Instance.GetPositionOfUnit(i) == attackFields[0]).ToList()[0]; if (unit.CanAttack) { dattack.Attack(closestEnemy); } } unit.CanAttack = false; //simulate thinking yield return(new WaitForSeconds(0.5f)); isInAction = false; }
GameObject FindSafestField(GameObject startPosField, List <GameObject> availableFields) { GameObject safestF = startPosField; //add the current field as first to check if it is the best place availableFields.Insert(0, startPosField); foreach (GameObject field in availableFields) { if (!isInDangerField(field)) { safestF = field; break; } } //find the weakest enemy in case all fields are endangered if (safestF == startPosField && isInDangerField(safestF)) { List <Unit> enemyList = Unit.UnitsList.Where(i => i.IsPlayerControlled).OrderBy(i => i.AttackPower).ToList(); List <GameObject> allAttFields = new List <GameObject>(); foreach (Unit enemy in enemyList) { UnitAttack enemy_attack = enemy.GetComponent <UnitAttack>(); allAttFields.Concat(enemy_attack.GetAttackTiles(BoardManager.Instance.GetPositionOfUnit(enemy), true, BoardManager.TileType.Attack)); } //sort by least endangered field (one field can be endangered from more than one unit) allAttFields = allAttFields.Distinct().ToList(); for (int i = allAttFields.Count; i >= 0; i--) { if (availableFields.Contains(allAttFields[i - 1])) { safestF = allAttFields[i - 1]; break; } } } return(safestF); }
public static void SpawnHostileUnit(Vector3 position, string guid) { GameModeType currentMode = Game.Instance.CurrentMode; if (currentMode == GameModeType.Default || currentMode == GameModeType.Pause) { BlueprintUnit blueprintUnit = Utilities.GetBlueprintByGuid <BlueprintUnit>(guid); if (blueprintUnit != null) { Player player = Game.Instance.Player; UnitEntityData target = player.Party.Random <UnitEntityData>(); UnitEntityData executor = Game.Instance.EntityCreator.SpawnUnit((BlueprintUnit)Utilities.GetBlueprintByGuid <BlueprintUnit>(guid), position, Quaternion.LookRotation(target.OrientationDirection), Game.Instance.CurrentScene.MainState); if (!executor.AttackFactions.Contains(Game.Instance.BlueprintRoot.PlayerFaction)) { executor.AttackFactions.Add(Game.Instance.BlueprintRoot.PlayerFaction); } executor.Commands.Run(UnitAttack.CreateAttackCommand(executor, target)); } } }
public void OnDestroy() { EventsAggregator.Units.RemoveListener <BaseUnit, HitInfo>(EUnitEvent.HitReceived, OnHitReceived); EventsAggregator.Units.RemoveListener <BaseUnit>(EUnitEvent.DeathCame, OnUnitDeath); EventsAggregator.Fight.RemoveListener(EFightEvent.Pause, OnFightPause); EventsAggregator.Fight.RemoveListener(EFightEvent.Resume, OnFightResume); EventsAggregator.Fight.RemoveListener(EFightEvent.MapComplete, OnMapComplete); EventsAggregator.Fight.RemoveListener(EFightEvent.MapFail, OnMapFail); if (_isAlly && UnitsConfig.Instance != null && UnitsConfig.Instance.IsHero(_unitData.Data.Key)) { EventsAggregator.Units.RemoveListener <ESkillKey>(EUnitEvent.SkillUsage, UseSkill); } _unitData = null; _lastTargetUnit = _targetUnit = null; _unitAttack = null; //_unitPathfinder = null; _model = null; _ui = null; }
private void Start() { if (this.gameObject.GetComponent <AttackManager>() == true) { attackManager = this.gameObject.GetComponent <AttackManager>(); } else { attackManager = new AttackManager(); } if (player == null) { player = GameObject.Find("Player"); } unitAttack = this.gameObject.AddComponent <UnitAttack>(); unitAttack.Initialize(this.gameObject); if (this.gameObject.GetComponent <UnitProfile>() == null) { unitProfile = this.gameObject.AddComponent <UnitProfile>(); unitProfile.Initialize(); } movement = this.gameObject.AddComponent <Movement>(); //Enemy doesn't need to initialize }
void Start() { gameManager = GameManager.Instance; unitAttack = GetComponent <UnitAttack>(); unitControl = GetComponent <UnitControl>(); mapControl = gameManager.ActiveMap; AIStateWaiting aiStateWaiting = gameObject.AddComponent <AIStateWaiting>(); aiStateWaiting.StateInit(); states.Add(aiStateWaiting.StateName, aiStateWaiting); AIStateMoving aiStateMoving = gameObject.AddComponent <AIStateMoving>(); aiStateMoving.StateInit(); states.Add(aiStateMoving.StateName, aiStateMoving); AIStateAttacking aiStateAttacking = gameObject.AddComponent <AIStateAttacking>(); aiStateAttacking.StateInit(); states.Add(aiStateAttacking.StateName, aiStateAttacking); State = "Waiting"; }
private static void Postfix(UnitAttack __instance) { UnitEntityData unit = __instance.Executor; if (!StatusWrapper.IsInCombat() || !unit.IsCurrentUnit()) { return; } bool attackingNearest = unit.Descriptor.State.HasCondition(UnitCondition.AttackNearest); bool confusedAttackNearest = false; if (unit.Descriptor.State.HasCondition(UnitCondition.Confusion)) { UnitPartConfusion part = unit.Get <UnitPartConfusion>(); if (part.State == ConfusionState.AttackNearest) { confusedAttackNearest = true; } } if (attackingNearest || confusedAttackNearest) { StatusWrapper.CurrentTurn().ForceToEnd(); } }
static void Postfix(UnitAttack __instance, AttackHandInfo attack) { TwoWeaponFightingDamagePenalty__OnEventAboutToTrigger__Patch.is_off_hand = false; }
static bool Prefix(UnitAttack __instance, AttackHandInfo attack) { TwoWeaponFightingDamagePenalty__OnEventAboutToTrigger__Patch.is_off_hand = (attack?.Hand != null && attack?.Hand == __instance.Executor?.Body?.SecondaryHand); return(true); }
public void OnDestroy() { EventsAggregator.Units.RemoveListener<BaseUnit, HitInfo>(EUnitEvent.HitReceived, OnHitReceived); EventsAggregator.Units.RemoveListener<BaseUnit>(EUnitEvent.DeathCame, OnUnitDeath); EventsAggregator.Fight.RemoveListener(EFightEvent.Pause, OnFightPause); EventsAggregator.Fight.RemoveListener(EFightEvent.Resume, OnFightResume); EventsAggregator.Fight.RemoveListener(EFightEvent.MapComplete, OnMapComplete); EventsAggregator.Fight.RemoveListener(EFightEvent.MapFail, OnMapFail); if (_isAlly && UnitsConfig.Instance != null && UnitsConfig.Instance.IsHero(_unitData.Data.Key)) { EventsAggregator.Units.RemoveListener<ESkillKey>(EUnitEvent.SkillUsage, UseSkill); } _unitData = null; _lastTargetUnit = _targetUnit = null; _unitAttack = null; //_unitPathfinder = null; _model = null; _ui = null; }
static bool IsFullAttackRestricted(bool isFullAttackRestrictedBecauseOfMoveAction, UnitAttack command) { if (IsInCombat() && command.Executor.IsInCombat) { if (command.Executor.IsMoveActionRestricted()) { return(true); } else if (command.IsIgnoreCooldown) { return(false); } } return(isFullAttackRestrictedBecauseOfMoveAction); }
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); }
private void Awake() { m_unitMovement = this.gameObject.AddComponent <UnitMovement>(); m_unitAnimation = this.gameObject.AddComponent <UnitAnimation>(); m_unitAttack = this.gameObject.AddComponent <UnitAttack>(); }