public void PercAction()
    {
        if (ThisUnit == null)
        {
            ThisUnit = gameObject.GetComponent <BasicUnit> ();
        }
        if (!isCreateList)
        {
            int xSelf, ySelf;
            xSelf = GridABS.NodeFromWorldPoint(transform.position).x;
            ySelf = GridABS.NodeFromWorldPoint(transform.position).y;
            for (int x = -Dist; x <= Dist; x++)
            {
                int local = Mathf.Abs(x);
                int func  = Dist - local;
                for (int y = -func; y <= func; y++)
                {
                    if (x == 0 && y == 0)
                    {
                        continue;
                    }
                    try {
                        var nodes = GridABS.GridOfArena[x + xSelf, y + ySelf];
                        if (nodes.TypeBloc == NodeA.NodeType.Wall)
                        {
                            continue;
                        }
                        SpriteRenderer localmarcer = ThisUnit.Manger.PoolElement;
                        if (nodes.UnitOnNode != null)
                        {
                            targetList.Add(nodes.UnitOnNode);
                            localmarcer.color = Color.yellow;
                        }
                        else
                        {
                            localmarcer.color = Color.magenta;
                        }

                        localmarcer.transform.position = nodes.Position;
                        ThisUnit.Manger.TrashNode.Add(localmarcer);
                    } catch { };
                }
            }
            isCreateList = true;
        }

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Physics.Raycast(ray, out hit, Mathf.Infinity);

        if (Input.GetKeyDown(KeyCode.Mouse0) && hit.rigidbody != null)
        {
            BasicUnit target = hit.rigidbody.GetComponent <BasicUnit> ();
            if (ThisUnit == target)
            {
                GetFinalAction();
            }
        }
    }
    Vector2 lastCollisionVelocity; // For calculating impulse.

    // Start is called before the first frame update
    void Start()
    {
        audio         = GetComponent <AudioSource>();
        rigidbody     = GetComponent <Rigidbody2D>();
        unit          = GetComponent <BasicUnit>();
        unit.onDeath += OnDeath;
    }
Exemple #3
0
 public void Reset()
 {
     marker.SetActive(false);
     targetVapireEnergy  = null;
     targetGiveEnergy    = null;
     isVampireListCreate = false;
     isGiveListCreate    = false;
 }
 // create a diamond shaped splotch extending <radius> tiles from (centerRow, centerCol)
 private void PlaceObstacle(int targetRow, int targetCol, BasicUnit obstaclePrefab)
 {
     var tile = _tiles[targetRow, targetCol];
     if (tile.UnitOnTile == null) {
         var obstacle = (BasicUnit) GameObject.Instantiate(obstaclePrefab);
         obstacle.transform.parent = tile.transform.parent;	// nest obstacle under the tilemap
         tile.UnitOnTile = obstacle;
     }
 }
Exemple #5
0
        //Опрацьовує юніта, який зайшов у місто
        public void GetUnits(BasicUnit unit)
        {
            bool needResend = false;

            if (PlayerId == unit.PlayerId)
            {
                if (unit.planedDestination != this)
                {
                    needResend = true;
                }
                else
                {
                    this.currWarriors += unit.warriorsCnt;
                    if (!saveOvercapedUnits && currWarriors > maxWarriors)
                    {
                        currWarriors = maxWarriors;
                    }
                }
            }
            else
            {
                unit.warriorsCnt = (ushort)Math.Round((2 - this.defPersent) * unit.warriorsCnt);

                if (currWarriors > unit.warriorsCnt)
                {
                    currWarriors -= unit.warriorsCnt;
                }
                else if (
                    (currWarriors < unit.warriorsCnt) ||
                    (
                        currWarriors == unit.warriorsCnt &&
                        ((PlayerId == 0 && equalsMeanCapturedForNeutral) ||
                         (equalsMeanCaptured))
                    )
                    )
                {
                    CityCaptureEvent captureCityEvent = new CityCaptureEvent(basicCityEvent, PlayerId, unit.PlayerId);
                    currWarriors = (ushort)(unit.warriorsCnt - currWarriors);
                    PlayerId     = unit.PlayerId;
                    Captured?.Invoke(captureCityEvent);
                }
                else if (currWarriors == unit.warriorsCnt)
                {
                    currWarriors = 0;
                }
            }

            if (needResend)
            {
                ResendUnit(unit.planedDestination, unit);
            }
            else
            {
                gameMap.Units.Remove(unit);
                UnitGet?.Invoke(new CityUnitsEvent(basicCityEvent, unit));
            }
        }
    public void GetUnitInfo()
    {
        BasicUnit localUnit = Units[UnitID];

        NameUnitText.text = localUnit.CorrectName;
        HPText.text       = localUnit.MaxHP.ToString();
        EPText.text       = localUnit.MaxEP.ToString();
        MovementText.text = localUnit.MaxMovement.ToString();
        UnitImage.sprite  = localUnit.GetComponent <SpriteRenderer>().sprite;
    }
Exemple #7
0
 public void Clean()
 {
     if (targetVapireEnergy != null && targetGiveEnergy != null)
     {
         targetVapireEnergy  = null;
         targetGiveEnergy    = null;
         isVampireListCreate = false;
         isGiveListCreate    = false;
     }
 }
Exemple #8
0
    public void SetElements()
    {
        transform.position = GridABS.NodeFromWorldPoint(transform.position).UnitPosition;
        GridABS.NodeFromWorldPoint(transform.position).UnitOnNode = this;
        unit   = GetComponentInChildren <BasicUnit> ();
        weapon = GetComponentInChildren <BasicWeapon> ();

        unit.gameObject.name   = unit.CorrectName;
        weapon.gameObject.name = weapon.CorrectName;
        unit.SetComponents();
    }
Exemple #9
0
 // Remove units from the countdown bar
 public void RemoveUnit(BasicUnit unit)
 {
     for (int i = targets.Count - 1; i >= 0; i--)
     {
         if (targets[i].Unit == unit)
         {
             Destroy(targets[i].Icon);
             targets.RemoveAt(i);
         }
     }
 }
 static void Main(string[] args)
 {
     _basicUnit = new BasicUnit();
     CreateCompany(5);
     CreateBrand(5);
     CreateProducts(5);
     CreateSkus(10);
     PurchaseProducts(5);
     SalesProducts(5);
     Console.ReadKey();
 }
 public virtual void MakeShoot(NodeA node)
 {
     if (_unit == null)
     {
         _unit = transform.parent.GetComponent <NetworkElement> ();
     }
     if (_bullet == null)
     {
         _bullet = Resources.Load <GameObject> ("Staff/Bullet") as GameObject;
     }
     _target = node.UnitOnNode.unit;
     StartCoroutine(MoveBullet(node));
 }
 public void SetEffects()
 {
     if (_lineEffect == null)
     {
         _lineEffect = Instantiate(Resources.Load("FX/PercGranade/LineSystemFX1") as GameObject, transform.position, Quaternion.identity, transform).GetComponent <ParticleSystem> ();
     }
     if (_granadelineFx == null)
     {
         _granadelineFx = (Resources.Load("FX/PercGranade/GranadeLineFX") as GameObject).GetComponent <ParticleSystem> ();
     }
     if (ThisUnit == null)
     {
         ThisUnit = GetComponent <BasicUnit> ();
     }
 }
        internal List <IUnit> GetUnits(Building building)
        {
            int lSide = -(WaveUnits.Count / 2);

            for (int i = 0; i < WaveUnits.Count; i++)
            {
                if (WaveUnits[i] is BasicUnit)
                {
                    BasicUnit unit = ((BasicUnit)WaveUnits[i]).NewInstace(WaveUnits[i].CurrentHealth, building.GetSpawn() + new Vector2(lSide, 0));
                    unit.SetTeam(((BasicUnit)WaveUnits[i]).TeamAssociation);
                    WaveUnits[i] = unit;
                    lSide++;
                }
            }
            return(WaveUnits);
        }
Exemple #14
0
    static public int GetIdFromUnit(BasicUnit unit)
    {
        if (unitNamesArray.Length == 0)
        {
            GetUnitArray();
        }

        for (int i = 0; i < unitNamesArray.Length; i++)
        {
            if (unit.CorrectName == unitNamesArray[i])
            {
                return(i);
            }
        }
        return(-1);
    }
Exemple #15
0
        public Rogue(BasicUnit unit) : base(unit)
        {
            Tag          = ClassTag.Rogue;
            HealthPoints = _healthPoints;
            ActionPoints = _actionPoints;

            // basic actions
            AddAction(new AttackAction(Unit, _basicAttackCost, _basicAttackDamage, _basicAttackMaxRange));

            MoveAction basicMove = new MoveAction(Unit, _basicMoveCost);

            AddAction(basicMove);
            AddAction(new LongMoveAction(basicMove));

            // class specific actions
            AddAction(new SpikesTrapAction(Unit, _basicSpikesTrapCost, _basicSpikesTrapMaxRange));
        }
Exemple #16
0
        public Warrior(BasicUnit unit) : base(unit)
        {
            Tag          = ClassTag.Warrior;
            HealthPoints = _healthPoints;
            ActionPoints = _actionPoints;

            // basic actions
            AddAction(new AttackAction(Unit, _basicAttackCost, _basicAttackDamage, _basicAttackMaxRange));

            MoveAction basicMove = new MoveAction(Unit, _basicMoveCost);

            AddAction(basicMove);
            AddAction(new LongMoveAction(basicMove));

            // class specific actions
            AddAction(new HookAction(Unit, _basicHookCost, _basicAttackDamage, _basicHookMaxRange));
        }
Exemple #17
0
        public Wizard(BasicUnit unit) : base(unit)
        {
            Tag          = ClassTag.Wizard;
            HealthPoints = _healthPoints;
            ActionPoints = _actionPoints;

            // basic actions
            AddAction(new AttackAction(Unit, _basicAttackCost, _basicAttackDamage, _basicAttackMaxRange));

            MoveAction basicMove = new MoveAction(Unit, _basicMoveCost);

            AddAction(basicMove);
            AddAction(new LongMoveAction(basicMove));

            // class specific actions
            AddAction(new TeleportAction(Unit, _basicTeleportCost));
        }
Exemple #18
0
        public static void Update(GameTime gameTime)
        {
            foreach (var spawnQueue in spawnQueues.Values)
            {
                if (spawnQueue.Count == 0)
                {
                    continue;
                }

                BasicUnit first = spawnQueue.Peek();
                if (first.UnitSpawnDelay <= 0)
                {
                    Scene.addItem(first);
                    spawnQueue.Dequeue();
                    return;
                }
                first.UnitSpawnDelay -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
        }
Exemple #19
0
    public void SetOwned(bool b)
    {
        owned = b;
        if (!owned)
        {
            MeshRenderer mr = GetComponent <MeshRenderer>();
            if (mr != null)
            {
                mr.sharedMaterial = red;
            }
        }
        BasicUnit basicUnit = GetComponent <BasicUnit>();

        if (basicUnit != null)
        {
            // Tinaxd set owner
            basicUnit.Owned = b;
        }
    }
Exemple #20
0
        //Створює юніта і задає йому шлях для руху
        public void SendUnit(BasicCity to)
        {
            ushort sendWarriors = GetAtkWarriorsWithoutAtk();

            if (sendWarriors == 0 || to == this)
            {
                return;
            }

            currWarriors -= sendWarriors;
            sendWarriors  = (ushort)Math.Round(sendWarriors * atkPersent);

            BasicUnit unit = CreateLinkedUnit(sendWarriors, to);

            if (unit != null)
            {
                UnitSend?.Invoke(new CityUnitsEvent(basicCityEvent, unit));
                gameMap.Units.Add(unit);
            }
        }
Exemple #21
0
    // Add units to the countdown bar
    public void RegisterUnit(BasicUnit unit)
    {
        if (!UnitTypeCDIconMapper.map.TryGetValue(unit.unit.type, out string iconPath))
        {
            return;
        }
        var        texture = (Texture)Resources.Load(iconPath);
        GameObject icon    = Instantiate(modelIcon);

        icon.GetComponent <RawImage>().texture = texture;

        var cdui = new CountDownUnitIcon();

        cdui.Unit = unit;
        cdui.Icon = icon;
        targets.Add(cdui);

        icon.GetComponent <RectTransform>().SetParent(this.transform);

        cdui.Icon.GetComponent <CountDownIcon>().TargetUnit = cdui.Unit;

        DecideIconPosition(cdui);
    }
        public void TransctionCompleateTest()
        {
            var con = new BasicUnit();
            var tc  = new Transaction(con);

            Stock skuinfo = con.Stocks.GetStockBySkuId(20);


            var tm = new TransactionMetadata
            {
                IsSales         = false,
                InvoiceNumber   = "123",
                SalesAmount     = 500,
                TransactionDate = DateTime.Today,
                Products        = new List <StockMetaData>
                {
                    new StockMetaData
                    {
                        SkuId     = skuinfo.SkuId,
                        BrandId   = skuinfo.BrandId,
                        CompanyId = skuinfo.CompnayId,
                        Amount    = 200,
                        ProductId = skuinfo.ProductId,
                        Quantity  = 10,
                        Rate      = 5
                    }
                }
            };


            tc.TransctionCompleate(tm);

            Stock skuinfoAfterTest = con.Stocks.GetStockBySkuId(20);

            Assert.AreEqual(skuinfo.Quantity - 10, skuinfoAfterTest.Quantity);
        }
 public bool IsAttackableBy(BasicUnit other)
 {
     return UnitTeam == Team.Neutral || (UnitTeam != other.UnitTeam);
 }
        void TKData(object n)
        {
            int    hasVal;
            double nodataV;
            double importLevel;

            double[] geoTansform = new double[6];

            CutData cutData = (CutData)n;

            importLevel = cutData.ImportLevel;
            Dataset demDs = Gdal.Open(cutData.DemPath, Access.GA_ReadOnly);
            Dataset slpDs = Gdal.Open(cutData.SlopePath, Access.GA_ReadOnly);

            demDs.GetRasterBand(1).GetNoDataValue(out nodataV, out hasVal);
            if (hasVal == 0)
            {
                throw new Exception("该栅格未设置Nodata!");
            }
            demDs.GetGeoTransform(geoTansform);

            int xTimes = (demDs.RasterXSize - 300) / 500;
            int xRemainder = (demDs.RasterXSize - 300) % 500;
            int yTimes = (demDs.RasterYSize - 300) / 500;
            int yRemainder = (demDs.RasterYSize - 300) % 500;
            int ax = xTimes, by = yTimes;

            if (xRemainder > 10)
            {
                ax++;
            }
            int x = cutData.cutIndex % ax;
            int y = cutData.cutIndex / ax;
            int xsize = 800, ysize = 800;

            if (x * 500 + 800 > demDs.RasterXSize)
            {
                xsize = demDs.RasterXSize - x * 500;
            }
            if (y * 500 + 800 > demDs.RasterYSize)
            {
                ysize = demDs.RasterYSize - y * 500;
            }

            double[] buffer      = new double[xsize * ysize];
            double[] slopebuffer = new double[xsize * ysize];
            demDs.GetRasterBand(1).ReadRaster(x * 500, y * 500, xsize, ysize, buffer, xsize, ysize, 0, 0);
            slpDs.GetRasterBand(1).ReadRaster(x * 500, y * 500, xsize, ysize, slopebuffer, xsize, ysize, 0, 0);

            BasicUnit bUnit = new BasicUnit(x * 500, y * 500, xsize, ysize,
                                            importLevel, buffer, slopebuffer, geoTansform, nodataV);

            List <Geometry> geolist = bUnit.Identify2();

            Console.WriteLine("一个图块儿计算完毕");
            lock (qthread)
            {
                foreach (Geometry item in geolist)
                {
                    qthread.WritePolygonShp(item);
                }
            }
            demDs.Dispose();
            slpDs.Dispose();
        }
Exemple #25
0
    public void PercAction()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Physics.Raycast(ray, out hit, Mathf.Infinity);

        if (ThisUnit == null)
        {
            ThisUnit = gameObject.GetComponent <BasicUnit> ();
        }
        if (ThisUnit.EP < EnergyCost)
        {
            ThisUnit.Manger.ShowInfoText("No energy", Color.white, transform.position);
            ThisUnit.Manger.SetTurnMode(-1);
            return;
        }

        if (!isVampireListCreate)
        {
            foreach (NetworkElement item in ThisUnit.Manger.ElementsInGame)
            {
                if (Vector3.Distance(item.transform.position, transform.position) < MaxDistantion && item.unit.Alive)
                {
                    SpriteRenderer localmarcer = ThisUnit.Manger.PoolElement;
                    localmarcer.transform.position = item.transform.position - Vector3.right * .25f - Vector3.back * .1f;
                    localmarcer.color = Color.magenta;
                    ThisUnit.Manger.TrashNode.Add(localmarcer);
                }
            }
            isVampireListCreate = true;
        }
        if (Input.GetKeyDown(KeyCode.Mouse0) && targetVapireEnergy == null && hit.rigidbody != null)
        {
            BasicUnit target = hit.rigidbody.GetComponent <BasicUnit> ();
            targetVapireEnergy = target;
            marker.SetActive(true);
            SpriteRenderer localmarcer = marker.GetComponent <SpriteRenderer> ();
            localmarcer.transform.position = target.transform.position - Vector3.right * .25f - Vector3.back * .1f;
            localmarcer.color = Color.magenta;
        }
        if (targetVapireEnergy == null)
        {
            return;
        }

        if (!isGiveListCreate)
        {
            ThisUnit.Manger.ClearGrid();
            foreach (NetworkElement item in ThisUnit.Manger.ElementsInGame)
            {
                if (Vector3.Distance(item.transform.position, transform.position) < MaxDistantion && item.unit != targetVapireEnergy && item.unit.Alive)
                {
                    SpriteRenderer localmarcer = ThisUnit.Manger.PoolElement;
                    localmarcer.transform.position = item.transform.position - Vector3.right * .25f - Vector3.back * .1f;
                    localmarcer.color = Color.yellow;
                    ThisUnit.Manger.TrashNode.Add(localmarcer);
                }
            }
            isGiveListCreate = true;
        }
        if (Input.GetKeyDown(KeyCode.Mouse0) && targetGiveEnergy == null && hit.rigidbody != null)
        {
            BasicUnit target = hit.rigidbody.GetComponent <BasicUnit> ();
            if (targetVapireEnergy != target)
            {
                targetGiveEnergy = target;
            }
        }
        if (targetGiveEnergy == null)
        {
            return;
        }

        GetFinalAction();
    }
 // create a building centered around (centerRow, centerCol)
 private void PlaceBuilding(int centerRow, int centerCol, int size, BasicUnit wallPrefab, Direction externalDoorSides)
 {
     // start/end row are the rows of the top and bottom diamond points
     int startRow = Mathf.Clamp(centerRow - size / 2, 0, _numRows);
     int endRow = Mathf.Clamp(centerRow + size / 2, 0, _numRows);
     int startCol = Mathf.Clamp(centerCol - size / 2, 0, _numCols);
     int endCol = Mathf.Clamp(centerCol + size / 2, 0, _numCols);
     var floorElevation = _tiles[centerRow, centerCol].Elevation;
     ClearArea(startRow, endRow, startCol, endCol, floorElevation);
     _doorLocations = GetDoorLocations(startRow, endRow - 1, startCol, endCol - 1, externalDoorSides);
     // place row walls
     for (int row = startRow; row < endRow; row++) {
         PlaceWall(row, startCol,   wallPrefab);
         PlaceWall(row, endCol - 1, wallPrefab);
     }
     // place column walls
     for (int col = startCol; col < endCol; col++) {
         PlaceWall(startRow,   col, wallPrefab);
         PlaceWall(endRow - 1, col, wallPrefab);
     }
 }
 private void PlaceWall(int row, int col, BasicUnit wallPrefab)
 {
     var tile = _tiles[row, col];
     // skip placing wall if it is a door spot.
     if (_doorLocations.Contains(new Coordinate(row, col))) {
         return;  //TODO: place a door object
     }
     if (!tile.UnitOnTile) { // only place wall if there is no obstruction
         var wall = (BasicUnit)GameObject.Instantiate(wallPrefab);
         wall.transform.parent = tile.transform.parent;	// nest obstacle under the tilemap
         tile.UnitOnTile = wall;
     }
 }
Exemple #28
0
 public abstract T Visit(BasicUnit v);
 public BasicUnitEvent(BasicUnit Unit)
 {
     unit = Unit;
 }
 public BasicUnitEvent(BasicUnitEvent @event)
 {
     unit = @event.unit;
 }
Exemple #31
0
        public void ResendUnit(BasicCity to, BasicUnit unit)
        {
            var path = BuildOptimalPath(to, out BasicCity realDest);

            unit.SetPath(path, realDest, to);
        }
Exemple #32
0
 void GetbasicUnit()
 {
     ThisUnit = GetComponent <BasicUnit> ();
 }