Пример #1
0
    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;
        }
    }
Пример #2
0
    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);
                }
            }
        }
    }
Пример #3
0
    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);
    }
Пример #4
0
 //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);
            }
        }
Пример #6
0
 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;
             }
         }
     }
 }
Пример #7
0
 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;
                 }
             }
         }
     }
 }
Пример #8
0
 //This function will choose if the target remains on the field.
 private void Action_IfDeadKillUnit(UnitCore target)
 {
     if (target.health < 0)
     {
         target.death();
     }
 }
Пример #9
0
    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);
    }
Пример #10
0
    void Awake()
    {
        arounds = new Collider[0];

        agent = GetComponent<NavMeshAgent> ();
        path  = new NavMeshPath();
        core = GetComponent<UnitCore> ();
    }
Пример #11
0
 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());
 }
Пример #12
0
 //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);
 }
Пример #13
0
    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());
    }
Пример #14
0
    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);
        }
    }
Пример #15
0
    //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);
        }
    }
Пример #16
0
    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);
    }
Пример #17
0
 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>();
 }
Пример #18
0
    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());
    }
Пример #19
0
    //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);
    }
Пример #20
0
 public void ManageUnitCores(UnitCore target, bool register)
 {
     if (register)
     {
         unitCores.Add(target);
     }
     else
     {
         unitCores.Remove(target);
     }
 }
Пример #21
0
 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);
     }
 }
Пример #22
0
    //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);
        }
    }
Пример #23
0
    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;
            }
        }
    }
Пример #24
0
    //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);
    }
Пример #25
0
    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);
        }
Пример #27
0
    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);
    }
Пример #28
0
        // 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);
        }
Пример #30
0
//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?
         *
         *
         * -*/
    }
Пример #31
0
 /* ########################## core mono functions ######################## */
 void Awake()
 {
     reactor = GetComponent<Reactor> ();
     core = GetComponent<UnitCore> ();
 }
Пример #32
0
 void Start()
 {
     unitCore = GetComponent <UnitCore>();
 }
Пример #33
0
 void RunEffect(UnitCore causer, State state, Effector targetEffect)
 {
     unitCore.RunEffector(new Source(causer, state), targetEffect, false);
 }
Пример #34
0
 public void RegisterUnit( UnitCore unit )
 {
     var l = unit.side == UnitSide.Side01 ? side01 : side02;
     if ( !l.Contains(unit) ) l.Add (unit);
 }