示例#1
0
    public static Unit Decorate(Unit unit, Spawner spawner)
    {
        switch (unit.type)
        {
        case UnitType.Base:
            unit.speed     = 0f;
            unit.size      = 4.5f;
            unit.height    = 2.4f;
            unit.maxHealth = 1000;
            break;

        case UnitType.Soldier:
            unit.speed = 1f;
            break;

        case UnitType.Archer:
            unit.speed             = .8f;
            unit.maxHealth         = 60;
            unit.attackRange       = 8f;
            unit.damage            = 30;
            unit.attackSpeed       = 35;
            unit.attackDamageDelay = 15;
            unit.DoDamageOverride  = () =>
            {
                spawner.SpawnProjectile(unit.position, ProjectileType.Arrow, unit, unit.attackTarget);
            };
            break;

        case UnitType.Priest:
            UnitMeta.DecoratePriest(unit, spawner);
            break;

        case UnitType.FireMage:
            unit.speed             = .6f;
            unit.maxHealth         = 50;
            unit.attackRange       = 11f;
            unit.damage            = 30;
            unit.attackSpeed       = 70;
            unit.attackDamageDelay = 20f;
            unit.DoDamageOverride  = () =>
            {
                spawner.SpawnProjectile(unit.position, ProjectileType.Fireball, unit, unit.attackTarget);
            };
            break;

        case UnitType.Assassin:
            UnitMeta.DecorateAssassin(unit);
            break;

        case UnitType.Linker:
            UnitMeta.DecorateLinker(unit);
            break;

        case UnitType.Sniper:
            UnitMeta.DecorateSniper(unit, spawner);
            break;
        }
        return(unit);
    }
示例#2
0
    public Unit SpawnUnit(Player player, Vector2 position, UnitType type)
    {
        var unit = new Unit(this.nextId++, type, player, position);

        unit.game = this.game;
        unit      = UnitMeta.Decorate(unit, this);
        unit.Initialize();
        this.game.units.Add(unit);
        return(unit);
    }
示例#3
0
        public async Task <IActionResult> Update(string id, [FromBody] UnitMeta unitMeta)
        {
            var result = await _unitService.Update(CurrentUser.TenantId, id, CurrentUser.Id, CurrentUser.FullName, unitMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
示例#4
0
文件: Game.cs 项目: ericyliu/autowar
    void BuyUnit(GameAction action)
    {
        if (action.slot > Player.UNIT_SLOTS - 1)
        {
            return;
        }
        var player = action.player;
        var cost   = UnitMeta.GetBuyUnitCost(action.unitType);

        if (player.gold < cost)
        {
            return;
        }
        player.gold -= cost;
        player.unitsToSpawn[action.slot] = action.unitType;
    }
示例#5
0
文件: UI.cs 项目: ericyliu/autowar
    void UpdateShopUI()
    {
        var player       = this.gameComponent.player;
        var unitsToSpawn = player.unitsToSpawn;

        for (int i = 0; i < Player.UNIT_SLOTS; i++)
        {
            Transform buttonTransform = this.shopPanel.GetChild(i);
            if (buttonTransform != null && unitsToSpawn[i] != UnitType.Null)
            {
                SetButtonText(buttonTransform.GetComponent <Button>(), unitsToSpawn[i].ToString());
                (buttonTransform as RectTransform).sizeDelta = new Vector2(160, 50);
            }
        }
        this.buyUnitButtons.ForEach(bub => bub.button.interactable = player.gold >= UnitMeta.GetBuyUnitCost(bub.type));
    }
示例#6
0
文件: UI.cs 项目: ericyliu/autowar
    public void OpenUnitShopRow(int slot)
    {
        this.CloseShop();
        var row             = this.innerShopPanel.GetChild(slot).Find("RowContainer");
        var buyableUnitList = row.Find("Units");

        UnitMeta.GetBuyableUnits(this.gameComponent.player.unitsToSpawn[slot]).ForEach(type =>
        {
            if (type == this.gameComponent.player.unitsToSpawn[slot])
            {
                return;
            }
            var button = Instantiate(this.buyUnitButtonPrefab, buyableUnitList).GetComponent <Button>();
            button.onClick.AddListener(() => this.BuyUnit(slot, type));
            button.interactable = this.gameComponent.player.gold >= UnitMeta.GetBuyUnitCost(type);
            this.SetButtonText(button, type.ToString() + " (" + UnitMeta.GetBuyUnitCost(type) + ")");
            this.buyUnitButtons.Add(new BuyUnitButton(button, type));
        });
        row.gameObject.SetActive(true);
    }
示例#7
0
    public void AddUnit(HexCell cell, UnitMeta meta)
    {
        if (cell && !cell.Unit)
        {
            var prefab = Instantiate(Resources.Load(String.Format("Units\\{0}", meta.Name)), new Vector3(0, 0, 0), Quaternion.Euler(0, 180, 0)) as GameObject;
            var unit   = prefab.GetComponent <HexUnit>();

            //Assign team number
            unit.Team = meta.Team;

            //Set base state
            if (PlayerTeam != meta.Team)
            {
                unit.ActPhase = ActPhase.Wait;
            }

            var teamNumber = unit.transform.Find("TeamNumber");
            var sprites    = GridResources.TeamNumberSprites;
            teamNumber.GetComponent <SpriteRenderer>().sprite = sprites[meta.SpriteIdx];

            unit.transform.SetParent(gameObject.transform, false);
            unit.Location = cell;
        }
    }
示例#8
0
        public async Task <ActionResultResponse> Insert(string tenantId, string creatorId, string creatorFullName, UnitMeta unitMeta)
        {
            if (!unitMeta.Translations.Any())
            {
                return(new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one unitTranslation.")));
            }

            var unitId = Guid.NewGuid().ToString();
            var unit   = new Unit
            {
                Id               = unitId,
                IsActive         = unitMeta.IsActive,
                ConcurrencyStamp = Guid.NewGuid().ToString(),
                TenantId         = tenantId,
                CreatorId        = creatorId,
                CreatorFullName  = creatorFullName,
                CreateTime       = DateTime.Now,
            };

            var result = await _unitRepository.Insert(unit);

            if (result <= 0)
            {
                return(new ActionResultResponse(result, _sharedResourceService.GetString("Something went wrong. Please contact with administrator.")));
            }

            var unitTranslations = new List <UnitTranslation>();

            foreach (var unitTranslation in unitMeta.Translations)
            {
                unitTranslations.Add(new UnitTranslation
                {
                    UnitId       = unit.Id,
                    LanguageId   = unitTranslation.LanguageId,
                    Name         = unitTranslation.Name.Trim(),
                    Description  = unitTranslation.Description?.Trim(),
                    Abbreviation = unitTranslation.Abbreviation?.Trim(),
                    UnsignName   = unitTranslation.Name.Trim().StripVietnameseChars().ToUpper(),
                    IsDelete     = unit.IsDelete,
                    TenantId     = tenantId,
                });

                var isExistsName = await _unitTranslationRepository.CheckExistsByName(tenantId, unit.Id, unitTranslation.Name);

                if (isExistsName)
                {
                    await RollbackInsert(tenantId, unitId);

                    return(new ActionResultResponse(-5, _resourceService.GetString("Unit name already exists.")));
                }

                if (!string.IsNullOrEmpty(unitTranslation.Abbreviation))
                {
                    var isExistsAbbreviation = await _unitTranslationRepository.CheckExistsByAbbreviation(tenantId, unit.Id, unitTranslation.Abbreviation);

                    if (isExistsAbbreviation)
                    {
                        await RollbackInsert(tenantId, unitId);

                        return(new ActionResultResponse(-6, _resourceService.GetString("Unit abbreviation already exists")));
                    }
                }
            }

            var resultInsertDetail = await _unitTranslationRepository.Inserts(unitTranslations);

            if (resultInsertDetail > 0)
            {
                return(new ActionResultResponse(resultInsertDetail, _resourceService.GetString("Add new unit successful.")));
            }

            await RollbackInsert(tenantId, unitId);

            return(new ActionResultResponse(-5, _resourceService.GetString("Can not insert new Unit. Please contact with administrator.")));
        }
示例#9
0
        public async Task <ActionResultResponse> Update(string tenantId, string id, string lastUpdateUserId, string lastUpdateFullName, UnitMeta unitMeta)
        {
            if (!unitMeta.Translations.Any())
            {
                return(new ActionResultResponse(-1, _sharedResourceService.GetString("Please enter at least one language.")));
            }

            var unitInfo = await _unitRepository.GetInfo(tenantId, id);

            if (unitInfo == null)
            {
                return(new ActionResultResponse(-2, _resourceService.GetString("Unit does not exists.")));
            }

            if (unitInfo.ConcurrencyStamp != unitMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-3, _resourceService.GetString("The Unit already updated by other people. You can not update this Unit.")));
            }

            unitInfo.IsActive           = unitMeta.IsActive;
            unitInfo.ConcurrencyStamp   = Guid.NewGuid().ToString();
            unitInfo.LastUpdateUserId   = lastUpdateUserId;
            unitInfo.LastUpdateFullName = lastUpdateFullName;
            unitInfo.LastUpdate         = DateTime.Now;

            await _unitRepository.Update(tenantId, id, unitInfo);

            foreach (var unitTranslation in unitMeta.Translations)
            {
                var unitTranslationInfo = await _unitTranslationRepository.GetInfo(unitInfo.Id, unitTranslation.LanguageId, unitInfo.TenantId);

                if (unitTranslation.Name != unitTranslationInfo.Name)
                {
                    var isExistsName = await _unitTranslationRepository.CheckExistsByName(tenantId, unitInfo.Id, unitTranslation.Name);

                    if (isExistsName)
                    {
                        return(new ActionResultResponse(-5, _resourceService.GetString("Can not insert new Unit. Please contact with administrator.")));
                    }
                }

                if (!string.IsNullOrEmpty(unitTranslation.Abbreviation) && unitTranslation.Abbreviation != unitTranslationInfo.Abbreviation)
                {
                    var isExistsAbbeviation = await _unitTranslationRepository.CheckExistsByAbbreviation(tenantId, unitInfo.Id, unitTranslation.Abbreviation);

                    if (isExistsAbbeviation)
                    {
                        return(new ActionResultResponse(-6, _resourceService.GetString("Can not insert new Unit. Please contact with administrator.")));
                    }
                }

                if (unitTranslationInfo != null)
                {
                    //unitTranslationInfo.ProductUnitId = unitTranslation.ProductUnitId;
                    //unitTranslationInfo.LanguageId = unitTranslation.LanguageId;
                    unitTranslationInfo.Name         = unitTranslation.Name;
                    unitTranslationInfo.Description  = unitTranslation.Description;
                    unitTranslationInfo.Abbreviation = unitTranslation.Abbreviation;
                    unitTranslationInfo.UnsignName   = unitTranslation.Name.Trim().StripVietnameseChars().ToUpper();

                    await _unitTranslationRepository.Update(unitInfo.Id, unitTranslation.LanguageId, unitInfo.TenantId, unitTranslationInfo);
                }
                else
                {
                    unitTranslationInfo = new UnitTranslation()
                    {
                        Abbreviation = unitTranslation.Abbreviation,
                        Description  = unitTranslation.Description,
                        LanguageId   = unitTranslation.LanguageId,
                        Name         = unitTranslation.Name,
                        TenantId     = unitInfo.TenantId,
                        UnitId       = id,
                        UnsignName   = unitTranslation.Name.Trim().StripVietnameseChars().ToUpper()
                    };

                    await _unitTranslationRepository.Insert(unitTranslationInfo);
                }
            }

            return(new ActionResultResponse(1, _resourceService.GetString("Update Unit successful.")));
        }