public void RefreshAll(UnitCore snapshot) { for (int count = 0; count < elements.Count; count++) { float newAmount = 0; switch (elements[count].resource) { case Defs.ResourceTypes.Health: newAmount = snapshot.Health.PCT(); break; case Defs.ResourceTypes.Stamina: newAmount = snapshot.Stamina.PCT(); break; } elements[count].fill.fillAmount = newAmount; if (elements[count].reductionAnimation) { if (elements[count].lastReportedVal > newAmount) { elements[count].sinceLastLoss = 1.2f; } else { elements[count].sinceLastLoss = 0; } } elements[count].lastReportedVal = newAmount; } }
public void UpdateGuideLines(UnitCore target) { for (int count = 0; count < elements.Count; count++) { if (elements[count].guideLines >= 100) { int lines = 0; float spacing = 0; switch (elements[count].resource) { case Defs.ResourceTypes.Health: lines = Mathf.FloorToInt(target.Health.Max / UI_Styles.i.unitHUD.guideLineSpacing); break; case Defs.ResourceTypes.Stamina: lines = Mathf.FloorToInt(target.Stamina.Max / UI_Styles.i.unitHUD.guideLineSpacing); break; } spacing = ((elements[count].fill.preferredWidth / 2) / lines); Transform guideLinesT = elements[count].root.GetChild(2); HorizontalLayoutGroup targetGroup = guideLinesT.GetComponent <HorizontalLayoutGroup>(); targetGroup.spacing = spacing; for (int instance = 0; instance < lines; instance++) { Instantiate(guideLine, guideLinesT); } } } }
void Start() { anim = GetComponent <Animator>(); unitCore = GetComponent <UnitCore>(); playerCore = GetComponent <PlayerCore>(); states = GetComponent <HERO_StateController>(); if (isLocalPlayer && isClient) { //HUD HUDPointer = GameObject.Find("HUD/WeaponCore").GetComponent <Image>(); HUDBackground = HUDPointer.transform.GetChild(0).GetComponent <Image>(); HUDBar[0] = HUDBackground.transform.GetChild(0).GetComponent <Image>(); HUDBar[1] = HUDBackground.transform.GetChild(1).GetComponent <Image>(); HUDItemBackground = HUDPointer.transform.GetChild(1).GetComponent <CanvasGroup>(); HUDItemBar = HUDItemBackground.transform.GetChild(0).GetComponent <Image>(); //Cursor Cursor.visible = false; Cursor.lockState = CursorLockMode.Confined; } //Test Weapons EquipWeapon(MasterListDatabase.i.FetchItem(0), 0); EquipWeapon(MasterListDatabase.i.FetchItem(2), 1); }
//This function will choose if the target remains on the field. public void Action_IfDeadKillUnit(UnitCore target) { if (target.health <= 0) { target.death(); } }
public void MoveUnit(UnitPresentation unitPresentation, Vector2Int position) { if (unitPresentation is null) { throw new ArgumentNullException(nameof(unitPresentation)); } if (!Contains(unitPresentation)) { throw new InvalidOperationException($"There is no unit {unitPresentation}!"); } var onPosition = this[position]; if (onPosition != null) { if (onPosition != unitPresentation) { throw new InvalidOperationException($"Position {position} is already occupied by {onPosition}."); } } else { UnitCore unit = presentationsToUnits[unitPresentation]; var oldPosition = unitsToPositions[unit]; positionsToUnits.Remove(oldPosition); unitsToPositions[unit] = position; positionsToUnits[position] = unit; state = state.BuildTransition(unitPresentation); } }
public void AddState(UnitCore causer, State newState) { if (newState.independent) { CreateNewInstanceOfState(causer, newState); } else { if (!activeStates.Contains(newState)) { CreateNewInstanceOfState(causer, newState); } else { if (newState.maxStacks != 0 && properties[activeStates.IndexOf(newState)].stacks != newState.maxStacks) { properties[activeStates.IndexOf(newState)].stacks++; } else { properties[activeStates.IndexOf(newState)].duration = newState.duration; } } } }
public void AddStates(UnitCore causer, List <State> newStates) { for (int count = 0; count < newStates.Count; count++) { if (newStates[count].independent) { CreateNewInstanceOfState(causer, newStates[count]); } else { if (!activeStates.Contains(newStates[count])) { CreateNewInstanceOfState(causer, newStates[count]); } else { if (newStates[count].maxStacks != 0 && properties[activeStates.IndexOf(newStates[count])].stacks != newStates[count].maxStacks) { properties[activeStates.IndexOf(newStates[count])].stacks++; } else { properties[activeStates.IndexOf(newStates[count])].duration = newStates[count].duration; } } } } }
//This function will choose if the target remains on the field. private void Action_IfDeadKillUnit(UnitCore target) { if (target.health < 0) { target.death(); } }
public void RegisterBlock(GameObject hit) { Debug.Log("Blocked!"); UnitCore target = hit.GetComponent <UnitCore>(); target.RunEffector(new Source(caller.unitCore, MasterListDatabase.i.FetchItem(itemID), caller), effector, true); }
void Awake() { arounds = new Collider[0]; agent = GetComponent<NavMeshAgent> (); path = new NavMeshPath(); core = GetComponent<UnitCore> (); }
public void StartSlowMotion(UnitCore victim) { update = false; StartCoroutine(CameraControl.i.TargetTemp(victim.transform, delay * 0.75f)); Time.timeScale = slowdownFactor; Time.fixedDeltaTime = Time.timeScale * 0.02f; StartCoroutine(Delay()); }
//Checks if a unit's health is in good enough standing to retaliate. //Further conditions should be added here specific to retaliation. public bool check_retaliate(UnitCore target) { if (target.health > 0) { canRetaliate = true; } return(canRetaliate); }
public override void onUse(Waypoint Current, GameObject CallingUnit, GameObject Target) { heal = Random.Range(0.2f, 0.3f) * CallingUnit.GetComponent <UnitCore>().health; UnitCore target_UnitCore = Target.GetComponent <UnitCore>(); Action_ModifyTargetHealth((int)heal, target_UnitCore); Action_SendUIColor(target_UnitCore, getColor()); }
void OnEnable() { music = GameObject.Find("GameController").GetComponent <HERO_MusicController>(); unitCore = GetComponent <UnitCore>(); inv = GetComponent <PlayerInventory>(); weaponCore = GetComponent <WeaponCore>(); regionMaster = GameObject.Find("Regions").transform; //Ability actionBarT = GameObject.Find("UI/HUD/ActionBar").transform; if (isClient) { for (int count = 0; count < 5; count++) { abilityKeys.Add(Binds.i.GetBind("Skill " + (count + 1)).key); } for (int count = 0; count < 10; count++) { itemKeys.Add(Binds.i.GetBind("Item " + (count + 1)).key); } } //Mount mountGroup = GameObject.Find("UI/HUD/ChannelBack").GetComponent <CanvasGroup>(); mountBar = GameObject.Find("UI/HUD/ChannelBack/ChannelBarBack/ChannelBar").GetComponent <Image>(); //Now pass all required values if (isLocalPlayer) { UI_HUD.i.target = GetComponent <UnitCore>(); UI_HUD.i.playerCore = UI_CharacterMenu.i.playerCore = this; } if (isServer) { availableSlots = PlayerClassToSlots(playerClass); for (int count = 0; count < 5; count++) { if (!equippedAbilities[count].equipped) { RpcHUDPingAbility(count, Defs.AbilityMode.Level); } } int[] skills = new int[5]; string[] keys = new string[5]; for (int count = 0; count < 5; count++) { keys[count] = abilityKeys[count].ToString(); skills[count] = -1; } RpcActionBar_Rebuild(skills, keys); } }
//If the unit is in good standing health wise, then it will retaliate against the recivingUnit. public void Attack_Retaliation(UnitCore RetaliatingUnit, UnitCore recivingUnit) { bool canTargetRetaliate = check_retaliate(RetaliatingUnit); if (canTargetRetaliate) { Retaliation(RetaliatingUnit, recivingUnit); } }
void RegisterHit(GameObject hit) { //Audio AudioController.i.CmdPlay3DItemSound(caller.playerCore.currentLocation, caller.hands[hand].equipped.ID, Defs.ItemSound.HitSound, transform.position, 0.8f, 10, 30, 0.85f, 1.15f); UnitCore target = hit.GetComponent <UnitCore>(); target.RunEffector(new Source(caller.unitCore, MasterListDatabase.i.FetchItem(itemID), caller), effector, false); }
void Start() { //Get Components mainCam = Camera.main; cam = mainCam.GetComponent <CameraControl>(); unitCore = GetComponent <UnitCore>(); player = GetComponent <CharacterController>(); anim = GetComponent <Animator>(); debug = GameObject.Find("DEBUG!").GetComponent <TextMeshProUGUI>(); }
IEnumerator debugwaitAttacker() { yield return(new WaitForSeconds(0.5f)); UnitCore thisUnit = MainUnit.GetComponent <UnitCore>(); UnitCore.targettingPackage package = thisUnit.getTargetandTactic(); package.SelectedTactic.onUse(currentNode, MainUnit, package.TargetList); StartCoroutine(debugwaitDefender()); }
//Check if the target is under 0 health. private bool Check_isDead(UnitCore target) { bool isDead = false; if (target.health < 0) { isDead = true; } return(isDead); }
public void ManageUnitCores(UnitCore target, bool register) { if (register) { unitCores.Add(target); } else { unitCores.Remove(target); } }
public void RegisterBlock(GameObject hit) { if (!hitTargets.Contains(hit.GetComponent <NetworkIdentity>().netId)) { hitTargets.Add(hit.GetComponent <NetworkIdentity>().netId); Debug.Log("Blocked!"); UnitCore target = hit.GetComponent <UnitCore>(); target.RunEffector(new Source(caller.unitCore, MasterListDatabase.i.FetchItem(itemID), caller), effector, true); Destroy(gameObject); } }
//Target: Specific //Handles retaliation private void Retaliation(UnitCore retaliatingUnit, UnitCore recivingUnit) { int damage = get_RetaliationDamage(retaliatingUnit); if (check_retaliate(retaliatingUnit)) { Attack_Target(damage, recivingUnit); Action_UpdateUIHealth(recivingUnit); Action_SendUIColor(recivingUnit, new Color32(255, 255, 51, 255)); Action_IfDeadKillUnit(recivingUnit); } }
public void TestIfBarierSuitableToHide( UnitCore unit, Vector3 precalculated_toEnemyVector, ref float global_min, ref Barier barier ) { var unit_position = unit.transform.position; //!!! CAUTION !!! // only work with 4 side points and 4 conner points !!!! float local_min = global_min; bool min_changed = false; Vector3 closest = Vector3.zero; Vector3 tmp; tmp = side_points[0].value - unit_position; if ( tmp.magnitude < global_min ) { closest = side_points[0].value; global_min = tmp.magnitude; min_changed = true; } foreach (var r in side_points[0].closest_conner_points) { tmp = r - unit_position; if ( tmp.magnitude < local_min ) { closest = r; local_min = tmp.magnitude; min_changed = true; } } tmp = side_points[2].value - unit_position; if ( tmp.magnitude < local_min ) { closest = side_points[2].value; local_min = tmp.magnitude; min_changed = true; } foreach (var r in side_points[2].closest_conner_points) { tmp = r - unit_position; if ( tmp.magnitude < local_min ) { closest = r; local_min = tmp.magnitude; min_changed = true; } } //!!! END CAUTION !!! if (min_changed) { if ( Physics.Linecast(closest, unit.transform.position, walls_mask) ) return; // if we must run over enemy to reach the barier then no if (Vector3.Angle (precalculated_toEnemyVector, closest -unit_position) > 50f) { barier = this; global_min = local_min; } } }
//Returns a list of targets that are opposed to the CallingUnit. public List <GameObject> get_TargetList(Waypoint CurrentWaypoint, UnitCore CallingUnit) { List <GameObject> targetList; if (CallingUnit.faction == "Player") { targetList = CurrentWaypoint.Enemies; } else { targetList = CurrentWaypoint.Allies; } return(targetList); }
public void RegisterHit(GameObject hit) { //Audio AudioController.i.CmdPlay3DItemSound(caller.playerCore.currentLocation, itemID, Defs.ItemSound.HitSound, transform.position, 0.8f, 10, 30, 0.85f, 1.15f); UnitCore target = hit.GetComponent <UnitCore>(); target.RunEffector(new Source(caller.unitCore, MasterListDatabase.i.FetchItem(itemID)), effector, false); if (targetLimit != 0) { targetsHit--; if (targetsHit == 0) { Destroy(gameObject); } } }
// Modifying methods. public void AddUnit(UnitCore unit, Vector2Int position) { if (unit is null) { throw new ArgumentNullException(nameof(unit)); } var onPosition = this[position]; if (onPosition != null) { throw new InvalidOperationException($"Position {position} is already occupied by {onPosition}."); } unit = unit.Clone(); unit.Connect(Presentation); presentationsToUnits[unit.Presentation] = unit; unitsToPositions[unit] = position; positionsToUnits[position] = unit; state = state.BuildTransition(unit.Presentation); }
void CreateNewInstanceOfState(UnitCore causer, State newState) { activeStates.Add(newState); //Search for awake effects List <State.Effect> awakeEffects = new List <State.Effect>(); for (int count = 0; count < newState.effects.Count; count++) { if (newState.effects[count].awakeEffect) { awakeEffects.Add(newState.effects[count]); } } //Create Duration List Properties newList = new Properties(); //Causer newList.causer = causer; //Apply awake effects for (int count = 0; count < awakeEffects.Count; count++) { RunEffect(properties[count].causer, activeStates[count], awakeEffects[count].effector); } //Setup duration newList.duration = newList.durationMax = newState.duration; //Setup ticks newList.tick = new List <int>(newState.effects.Count); for (int count = 0; count < newState.effects.Count; count++) { newList.tick.Add(newState.effects[count].tickLength); } newList.stacks = 1; properties.Add(newList); }
// Support method. private UnitCore BuildUnit(System.Random random, Vector2Int position, MapPresentation map, ref int added) { // Initialize unit. UnitCore unit; if (UnitTemplates == null || UnitTemplates.Length == 0) { unit = new UnitCore(); } else { unit = UnitTemplates[random.Next(UnitTemplates.Length)].Clone(); } // Place unit. unit.Name = $"Unit {added++}"; Vector3 point = new Vector3(position.x, map[position].Height, position.y); unit.Move(new MovementAction(point - unit.Body.Position, adjustVelocity: false)); return(unit); }
public UnitCore RemoveUnit(UnitPresentation unitPresentation) { if (unitPresentation is null) { throw new ArgumentNullException(nameof(unitPresentation)); } if (!Contains(unitPresentation)) { throw new InvalidOperationException($"There is no unit {unitPresentation}!"); } UnitCore unit = presentationsToUnits[unitPresentation]; unit.Disconnect(); presentationsToUnits.Remove(unitPresentation); var position = unitsToPositions[unit]; positionsToUnits.Remove(position); unitsToPositions.Remove(unit); state = state.BuildTransition(unitPresentation); return(unit); }
//We need to really consider just what we're going to do for attacks. //Tactics should be able to target ally units //Target: Random Enemy //Light Damage, No retaliate, Yellow UI public void LightAttack(Waypoint CurrentWaypoint, UnitCore CallingUnit, int NumberOfTargets, bool canRetaliate) { //NEW SETUP. Calculate everything first, and then send an order sequence to the camera so that it can do it's job. CleanBools(); List <GameObject> targetList = get_TargetList(CurrentWaypoint, CallingUnit); List <UnitCore> target = get_RandomTarget(targetList, NumberOfTargets); int damage, index = 0; foreach (UnitCore troop in target) { index++; damage = get_DamageLight(CallingUnit); Attack_Target(damage, troop); if (canRetaliate) { Attack_Retaliation(troop, CallingUnit); } if (Check_isDead(CallingUnit)) { break; //If the retaliation marks the unit for death, then break out of loop. } } //So now what do we actually have? /*All of these units have had their health reduced, but only that. We know where the loop stopped. * * Let's assume the countine is a required element. We don't know what the end system will be but we can describe some aspects: * -Countine ladder downwards * -Modular code * -Calculates things inside the countine * * //OUTSIDE COUNTINE * -Targets can be calculated outside. * -Who retaliates? * * * -*/ }
/* ########################## core mono functions ######################## */ void Awake() { reactor = GetComponent<Reactor> (); core = GetComponent<UnitCore> (); }
void Start() { unitCore = GetComponent <UnitCore>(); }
void RunEffect(UnitCore causer, State state, Effector targetEffect) { unitCore.RunEffector(new Source(causer, state), targetEffect, false); }
public void RegisterUnit( UnitCore unit ) { var l = unit.side == UnitSide.Side01 ? side01 : side02; if ( !l.Contains(unit) ) l.Add (unit); }