コード例 #1
0
ファイル: ShopItem.cs プロジェクト: Chobotov/Project-Battle
    private void OnEnable()
    {
        if (itemType == ItemType.Unit)
        {
            unit = GameManager.Instance.allUnits[id];
        }
        else
        {
            unit = GameManager.Instance.towerUpdates[id];
        }

        if (unit.GetComponent <UnitData>().unitProperties.isPurchased == true)
        {
            buyButton.gameObject.SetActive(false);
        }

        dataHealth     = unit.GetComponent <UnitData>().dataHealth;
        unitProperties = unit.GetComponent <UnitData>().unitProperties;

        image.sprite = unit.GetComponent <SpriteRenderer>().sprite;
        image.SetNativeSize();

        price           = unitProperties.CoinsPrice;
        coinsPrice.text = $"{price}";

        titleText.text     = unit.name;
        healthText.text    = $"{dataHealth.Health}";
        damageText.text    = $"{unitProperties.Damage}";
        manaPriceText.text = $"{unitProperties.ManaPrice}";
        speedText.text     = $"{unitProperties.Speed}";
    }
コード例 #2
0
 private void FullUpdate()
 {
     CommonProperties.Populate(this);
     UnitProperties.Populate(this);
     GizmoProperties.Populate(this);
     LastFullUpdate = DateTime.UtcNow;
 }
コード例 #3
0
    /// <summary>
    /// Build the specified unity.
    /// </summary>
    /// <param name="toBuild">The unit to be built</param>
    public void build(GameObject toBuild)
    {
        UnitProperties     properties        = toBuild.GetComponent <UnitProperties> ();
        BuildingProperties factoryProperties = buildFactory.GetComponent <BuildingProperties> ();

        if (properties != null && factoryProperties != null)
        {
            //calculate reduced cost according to factory level
            int lvl = factoryProperties.level;
            int f   = costReduced(properties.foodCost, lvl);
            int w   = costReduced(properties.woodCost, lvl);
            int i   = costReduced(properties.ironCost, lvl);
            //check if there are enough resources
            if (buildSuccess(f, w, i, properties.unitCost))
            {
                toBuild.SetActive(true);

                GameObject newUnit = Instantiate(toBuild, GameObject.Find("PlayerUnits").transform) as GameObject;
                newUnit.transform.position     = new Vector3(buildFactory.transform.position.x - 5, 1.4f, buildFactory.transform.position.z);
                newUnit.transform.name         = toBuild.name;
                Camera.main.transform.position = new Vector3(newUnit.transform.position.x, Camera.main.transform.position.y, newUnit.transform.position.z - Camera.main.transform.position.y);
            }
            //else print error message
            else
            {
                createPopUp(toBuild.name, f, w, i, properties.unitCost);
            }
        }
    }
コード例 #4
0
 /// <summary>
 /// Hit unit target
 /// </summary>
 private void hit()
 {
     if (hasNewTarget)
     {
         //if there is a new target, get all needed variables for this target
         tragetProp         = target.GetComponent <UnitProperties> ();
         tragetBuildingProp = target.GetComponent <BuildingProperties> ();
         fighterProp        = transform.GetComponent <UnitProperties> ();
         hasNewTarget       = false;
         nextActionTime     = Time.time + fighterProp.actionSpeed;
     }
     if (target != null)
     {
         //Hit every X time, handle building and units
         if (Time.time >= nextActionTime)
         {
             if (tragetProp != null)
             {
                 tragetProp.life -= findDamage(target);
                 isTargetDead     = tragetProp.life <= 0;
             }
             else if (tragetBuildingProp != null)
             {
                 tragetBuildingProp.life -= fighterProp.buildingDamage;
                 isTargetDead             = tragetBuildingProp.life <= 0;
             }
             if (isTargetDead)
             {
                 target = null;
             }
             nextActionTime = Time.time + fighterProp.actionSpeed;
         }
     }
 }
コード例 #5
0
 void OnTriggerStay(Collider other)
 {
     if (Attacking)
     {
         Debug.Log(other.tag);
         if (other.tag.Equals("Player"))
         {
             UnitProperties eProps = other.GetComponent <UnitProperties>() ?? other.transform.parent.GetComponent <UnitProperties>();
             if (!eProps.invincible)
             {
                 eProps.Health--;
                 if (eProps != null)
                 {
                     Debug.Log("Enemy Health: " + eProps.Health);
                     transform.parent.GetComponent <Animator>().SetTrigger("Flee");
                 }
                 else
                 {
                     Debug.Log("Enemy Health: 0");
                     transform.parent.GetComponent <Animator>().SetBool("attacking", false);
                 }
             }
         }
     }
 }
コード例 #6
0
 void Awake()
 {
     properties = GetComponent <UnitManager>().GetProperties();
     InitializeUnit();
     animator       = GetComponent <Animator>();
     gloveColliders = new List <Collider>(GetComponentsInChildren <Collider>());
     gloves         = new List <Glove>(GetComponentsInChildren <Glove>());
 }
コード例 #7
0
    /// <summary>
    /// Makes the unit move target, if there's no target, give one
    /// </summary>
    private void moveToTarget()
    {
        if (hasDestination)
        {
            transform.LookAt(destination);
            transform.position += transform.forward * Time.smoothDeltaTime * speed;

            //Arrive on target
            if (targetGO != null)
            {
                if (targetGO.tag.Equals("FriendlyUnit"))
                {
                    if ((transform.position - destination).magnitude <= 0.5f)
                    {
                        actionOnArrive();
                    }
                }
                else if (targetGO.tag.Equals("FriendlyBuilding"))
                {
                    if ((transform.position - destination).magnitude <= 1.0f)
                    {
                        actionOnArrive();
                    }
                }
            }
        }
        else
        {
            targetList = GameObject.FindGameObjectsWithTag("FriendlyUnit");
            if (targetList.Length > maximumNumberPlayerUnitsToAttackPlayerBase)
            {
                targetGO = targetList [Random.Range(0, targetList.Length)];
            }
            else
            {
                targetGO = baseBuilding;
            }
            tragetProp         = targetGO.GetComponent <UnitProperties> ();
            tragetBuildingProp = targetGO.GetComponent <BuildingProperties> ();
            hasDestination     = true;
        }
        if (targetGO != null)
        {
            if (targetGO.tag.Equals("FriendlyBuilding"))
            {
                destination = targetGO.transform.position + new Vector3(4, 0, 0);
            }
            else
            if ((transform.position - targetGO.transform.position + new Vector3(1, 0, 0)).magnitude > 1f)
            {
                destination = targetGO.transform.position + new Vector3(1, 0, 0);
            }
        }
        else
        {
            hasDestination = false;
        }
    }
コード例 #8
0
    public void CreateUnit(int x, int y, int owner)
    {
        UnitProperties unit = new UnitProperties();

        unitcontroller.unitProperties.Add(new Vector2Int(x, y), unit);

        Vector3    truecoords = hexcalculator.HexToPixel(x, y);
        GameObject instance   = Instantiate(infantry, truecoords, Quaternion.Euler(0, 0, 0));
    }
コード例 #9
0
 void Start()
 {
     //Initialise variables
     tragetProp         = null;
     tragetBuildingProp = null;
     fighterProp        = null;
     hasNewTarget       = false;
     isTargetDead       = false;
 }
コード例 #10
0
        public UnitRepository Add(UnitProperties unit)
        {
            if (_units.ContainsKey(unit.Key))
            {
                throw new DuplicateUnitException(unit.Key.ToString());
            }

            _units.Add(unit.Key, unit);
            return(this);
        }
コード例 #11
0
 void Start()
 {
     //initialise variables
     properties     = transform.GetComponent <UnitProperties> ();
     speed          = properties.speed;
     destination    = transform.position;
     hasDestination = false;
     targetList     = GameObject.FindGameObjectsWithTag("FriendlyUnit");
     fighterProp    = transform.GetComponent <UnitProperties> ();
     nextActionTime = Time.time + fighterProp.actionSpeed;
 }
コード例 #12
0
 public static async Task <UnitRepository> AddOrUpdateCurrencyUnits(this UnitRepository unitRepository, ICurrencyDataLoader loader)
 {
     foreach (var item in await loader.LoadCurrencyItem())
     {
         var unit = new Unit(DefaultCategories.Currency, item.CurrencyCode);
         unitRepository[unit] = new UnitProperties(unit)
         {
             Abbreviations = new string[] { item.CurrencySymbol },
         };
     }
     return(unitRepository);
 }
コード例 #13
0
    void Start()
    {
        //Initialise variables
        associatedResource       = null;
        hasNewAssociatedResource = false;
        if (gatherAmount == 0)
        {
            gatherAmount = 5;
        }

        unitProperties = transform.GetComponent <UnitProperties> ();
    }
コード例 #14
0
ファイル: ExerciseController.cs プロジェクト: runvs/LD30
    void Start()
    {
        _name           = transform.parent.parent.FindChild("TeamMemberName").GetComponent <Text>().text;
        _attribute      = GetComponentInChildren <Text>().text.ToLower();
        _unitProperties = GameObject.FindGameObjectWithTag("UnitProperties").GetComponent <UnitProperties>();

        var button = GetComponent <Button>();

        button.onClick.AddListener(() =>
        {
            _unitProperties.Exercise(_name, _attribute);
        });
    }
コード例 #15
0
 private void FastUpdate()
 {
     try
     {
         CommonProperties.Update(this);
         UnitProperties.Update(this);
         GizmoProperties.Update(this);
     }
     catch (Exception ex)
     {
         Core.Logger.Warn($"Fast Update Failed.", ex);
     }
 }
コード例 #16
0
    void Start()
    {
        //Initialise variables
        properties           = transform.GetComponent <UnitProperties> ();
        speed                = properties.speed;
        destination          = transform.position;
        hasDestination       = false;
        stoppedCurrentAction = false;
        attackTargetGiven    = false;

        gatherer = transform.GetComponent <GatherController> ();
        fighter  = transform.GetComponent <FighterController> ();
    }
コード例 #17
0
 private void FullUpdate()
 {
     try
     {
         CommonProperties.Populate(this);
         UnitProperties.Populate(this);
         GizmoProperties.Populate(this);
         LastFullUpdate = DateTime.UtcNow;
     }
     catch (Exception ex)
     {
         Core.Logger.Warn($"Full Update Failed.", ex);
     }
 }
コード例 #18
0
    /// <summary>
    /// Build the unit given in class attribute
    /// </summary>
    public void build()
    {
        UnitProperties     properties        = toBuild.GetComponent <UnitProperties> ();
        BuildingProperties factoryProperties = buildFactory.GetComponent <BuildingProperties> ();

        toBuild.SetActive(true);
        GameObject newUnit = Instantiate(toBuild, GameObject.Find("EnemyUnits").transform) as GameObject;

        newUnit.transform.position = new Vector3(buildFactory.transform.position.x - 5, 1.4f, buildFactory.transform.position.z);
        newUnit.transform.name     = toBuild.name;
        EnemyUnitController euc = newUnit.AddComponent <EnemyUnitController> ();

        euc.baseBuilding = playerBaseBuilding;
    }
コード例 #19
0
ファイル: MeleeUnit.cs プロジェクト: gruppe9/Unity-gruppe9
 public override void Attack(UnitProperties target)
 {
     if (actionPoints >= attackCost && attackCost != 0 && damage >= 0)
     {
         if (isNotTesting)
         {
             lastTarget = target;
             anim.SetTrigger("Attack");
         }
         target.Health -= damage;
         actionPoints -= attackCost;
         Debug.Log("Enemy hit");
     }
     else
     {
         Debug.Log("Error 520: Ranged unit not enough action points - Or damage is less than zero");
     }
 }
コード例 #20
0
    private void SetDataProperties()
    {
        Sprite    sprite        = unitProperties.sprite;
        Side      side          = unitProperties.side;
        State     state         = unitProperties.state;
        UnitClass unitClass     = unitProperties.unitClass;
        int       Damage        = unitProperties.Damage;
        int       Speed         = unitProperties.Speed;
        int       manaPrice     = unitProperties.ManaPrice;
        int       coinsPrice    = unitProperties.CoinsPrice;
        float     Distance      = unitProperties.Distance;
        float     AttackDelay   = unitProperties.AttackDelay;
        bool      isPurchased   = unitProperties.isPurchased;
        bool      isCurrentUnit = unitProperties.isCurrentUnit;

        unitProperties = ScriptableObject.CreateInstance(typeof(UnitProperties)) as UnitProperties;
        unitProperties.SetSprite(sprite);
        unitProperties.SetEnum(side, state, unitClass);
        unitProperties.SetInt(Damage, Speed, manaPrice, coinsPrice);
        unitProperties.SetFloat(Distance, AttackDelay);
        unitProperties.SetBool(isPurchased, isCurrentUnit);
    }
コード例 #21
0
    // Use this for initialization
    void Start()
    {
        switch (unitName)
        {
        case "Player":
            properties = PlayerProperties.props;
            break;

        case "Opponent":
            properties = OpponentProperties.props;
            break;

        case "Hunter":
            properties = HunterProperties.props;
            break;

        case "Ball":
            properties = BallProperties.props;
            break;

        case "Game":
            properties = GameProperties.props;
            break;

        default:
            Debug.Log("No properties found for " + unitName);
            enabled = false;
            return;
        }

        text      = GetComponentInChildren <Text>();
        text.text = properties.GetType().Name;

        constraints = GetComponentsInChildren <SliderConstraint>();

        // TODO Right now we have prebuilt UI elements, later should be dynamic.
        //for each range value create a new min max slider as child?
        //for each single value create a new slider as child?
    }
コード例 #22
0
        public ActionResult Create(UnitFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Clients = GetClientList();

                return(View("Create", viewModel));
            }

            Address newAddress = new Address(viewModel.Civic,
                                             viewModel.Street,
                                             viewModel.City,
                                             viewModel.ZipCode);


            UnitProperties newUnitProperties = new UnitProperties(newAddress,
                                                                  true,
                                                                  viewModel.YearBuilt,
                                                                  viewModel.Price,
                                                                  viewModel.Title,
                                                                  viewModel.Description,
                                                                  viewModel.Rooms,
                                                                  viewModel.Bedrooms,
                                                                  viewModel.Bathrooms,
                                                                  viewModel.Garages,
                                                                  viewModel.CentralAirCondition);


            Unit newProperty = new Unit(1,
                                        newUnitProperties,
                                        viewModel.GetDateTime());

            _context.Units.Add(newProperty);
            _context.SaveChanges();

            return(RedirectToAction("List", "Units"));
        }
コード例 #23
0
ファイル: TrinityPlayer.cs プロジェクト: honorbuddy/Trinity
 private void UpdateProperties()
 {
     CommonProperties.Update(this);
     UnitProperties.Update(this);
 }
コード例 #24
0
ファイル: TrinityPlayer.cs プロジェクト: honorbuddy/Trinity
 public override void OnUpdated()
 {
     Attributes.Update(CommonData);
     CommonProperties.Populate(this);
     UnitProperties.Populate(this);
 }
コード例 #25
0
ファイル: Unit ExtraClasses.cs プロジェクト: choephix/G11
 internal void Init( UnitProperties props )
 {
     _armor = props.armor;
     _health = props.maxHealth;
     _maxHealth = props.maxHealth;
     _maxActions = Config.BASE_UNIT_ACTIONS;
     ResetActionPoints();
 }
コード例 #26
0
ファイル: UnitAI.cs プロジェクト: TowerDef/TowerDefense
 private void Awake()
 {
     unitProperties  = this.gameObject.GetComponent <UnitProperties> ();
     wayPointManager = FindObjectOfType(typeof(WaypointManager)) as WaypointManager;
     gameManager     = FindObjectOfType(typeof(GameManager)) as GameManager;
 }
コード例 #27
0
 public abstract void Attack(UnitProperties target);
コード例 #28
0
ファイル: TrinityPlayer.cs プロジェクト: ysj1995/Trinity
 private void UpdateProperties()
 {
     CommonProperties.Populate(this);
     UnitProperties.Populate(this);
     PlayerProperties.Populate(this);
 }
コード例 #29
0
 void Start()
 {
     player         = GameObject.FindWithTag("Player");
     unitProperties = unit.GetComponent <UnitProperties>();
     playerUnits    = player.GetComponent <PlayerUnits>();
 }
コード例 #30
0
ファイル: MapStuff.cs プロジェクト: gruppe9/Unity-gruppe9
    /// <summary>
    /// generate a path to a destination
    /// </summary>
    /// <param name="destination"></param>
    /// <returns></returns>
    public List<Node> GeneratePath(Vector3 destination, UnitProperties unit)
    {
        List<Node> currentPath = null;

        int x = (int)destination.x / tileSize;
        int z = (int)destination.z / tileSize;
        Debug.Log("started pathfinding with input: " + x + ", " + z);

        #region invalid input checks

        if (x < 0)
        {
            Debug.Log("invalid corrdinats: x is less than 0");
            return new List<Node>();
        }
        if (x > mapSizeX)
        {
            Debug.Log("invalid corrdinats: x is larger than map size");
            return new List<Node>();
        }
        if (z < 0)
        {
            Debug.Log("invalid corrdinats: z is less than 0");
            return new List<Node>();
        }
        if (z > mapSizeZ)
        {
            Debug.Log("invalid corrdinats: z is larger than map size");
            return new List<Node>();
        }

        #endregion
        Debug.Log("input is valid");

        Dictionary<Node, float> dist = new Dictionary<Node, float>();
        Dictionary<Node, Node> prev = new Dictionary<Node, Node>();
        List<Node> unvisited = new List<Node>();

        Node source = graph[
            (int)unit.transform.position.x / tileSize,
            (int)unit.transform.position.z / tileSize
            ];

        Node target = graph[
            x,
            z
            ];

        dist[source] = 0;
        prev[source] = null;

        // initialize nodes to have infinity distance
        foreach (Node v in graph)
        {
            if (v != source)
            {
                dist[v] = Mathf.Infinity;
                prev[v] = null;
            }
            unvisited.Add(v);
        }
        while (unvisited.Count > 0)
        {
            Node u = null;

            foreach (Node possibleU in unvisited)
            {
                if (u == null || dist[possibleU] < dist[u])
                {
                    u = possibleU;
                }
            }

            if (u == target)
            {
                break;
            }

            unvisited.Remove(u);

            foreach (Node v in u.neighbours)
            {
                float alt = dist[u] + u.DistanceTo(v);
                //float alt = dist[u] + CostToEnterTile(u, v);
                if (alt < dist[v])
                {
                    dist[v] = alt;
                    prev[v] = u;
                }
            }
        }

        if (prev[target] == null)
        {
            Debug.Log("wtf I can't find my target");
            return new List<Node>();
        }

        currentPath = new List<Node>();

        Node curr = target;
        while (curr != null)
        {
            currentPath.Add(curr);
            curr = prev[curr];
        }

        currentPath.Reverse();

        return currentPath;
    }
コード例 #31
0
 private void FastUpdate()
 {
     CommonProperties.Update(this);
     UnitProperties.Update(this);
     GizmoProperties.Update(this);
 }
コード例 #32
0
 public override void OnUpdated()
 {
     CommonProperties.Update(this);
     UnitProperties.Update(this);
     GizmoProperties.Update(this);
 }
コード例 #33
0
 public override void OnCreated()
 {
     CommonProperties.Populate(this);
     UnitProperties.Populate(this);
     GizmoProperties.Populate(this);
 }
コード例 #34
0
ファイル: TileMap.cs プロジェクト: gruppe9/Unity-gruppe9
    public void GeneratePathTo(Vector3 point, UnitProperties unit)
    {
        int x = (int)(point.x / tileSize);
        int z = (int)(point.z / tileSize);
        Debug.Log(x +", " + z);

        //clear out our units old path
        unit.currentPath = null;

        Dictionary<Node, float> dist = new Dictionary<Node, float>();
        Dictionary<Node, Node> prev = new Dictionary<Node, Node>();

        // setup the Q -- the list of unchecked nodes
        List<Node> unvisited = new List<Node>();

        Node source = graph[
                            unit.tileX,
                            unit.tileZ
                            ];

        Node target = graph[
                             x,
                             z
                             ];
        dist[source] = 0;
        prev[source] = null;

        //initialize everything to have infinity distance
        foreach (Node v in graph)
        {
            if (v != source)
            {
                dist[v] = Mathf.Infinity;
                prev[v] = null;
            }
            unvisited.Add(v);
        }
        while (unvisited.Count > 0)
        {
            //quick and dirty version, slow but short
            //consider having unvisited be priority queue or some other self sorting ,
            //optimized data structure
            //Node u = unvisited.OrderBy(n => dist[n]).First();

            //little faster
            //u is going to be the invisited node with the smallest distance
            Node u = null;
            foreach (Node possibleU in unvisited)
            {
                if (u == null || dist[possibleU] < dist[u])
                {
                    u = possibleU;
                }

            }

            if (u == target)
            {
                break; // exit the while loop
            }
            unvisited.Remove(u);

            foreach (Node v in u.neighbours)
            {
                //float alt = dist[u] + u.DistanceTo(v);
                float alt = dist[u] + CostToEnterTile(u.x, u.z, v.x, v.z);
                if (alt < dist[v])
                {
                    dist[v] = alt;
                    prev[v] = u;
                }
            }
        }
        // if we get here, then either we found the shortest route
        // to our target, or there is no route to our target
        if (prev[target] == null)
        {
            //no route to our between target and source
            return;
        }
        List<Node> currentPath = new List<Node>();

        Node curr = target;

        //step through the "prev" chain and add it to our path
        while (curr != null)
        {
            currentPath.Add(curr);
            curr = prev[curr];
        }
        //right now the currentPath describes a route from our target to our source
        //so we need to invert it!
        currentPath.Reverse(); // REVERSE!
        unit.currentPath = currentPath;
    }