Пример #1
0
 void Start()
 {
     if (inventoryStorage == null)
     {
         inventoryStorage = transform.GetChild(0).GetComponent <InventoryStorage>();
     }
 }
Пример #2
0
        public static void GetArmyContractStorageAndSize(Contract contract, out InventoryStorage storage, out int size)
        {
            CurrentPlayer   currentPlayer  = Service.Get <CurrentPlayer>();
            IDataController dataController = Service.Get <IDataController>();

            switch (contract.DeliveryType)
            {
            case DeliveryType.Starship:
                storage = currentPlayer.Inventory.SpecialAttack;
                size    = dataController.Get <SpecialAttackTypeVO>(contract.ProductUid).Size;
                return;

            case DeliveryType.Hero:
                storage = currentPlayer.Inventory.Hero;
                size    = dataController.Get <TroopTypeVO>(contract.ProductUid).Size;
                return;

            case DeliveryType.Champion:
                storage = currentPlayer.Inventory.Champion;
                size    = dataController.Get <TroopTypeVO>(contract.ProductUid).Size;
                return;

            default:
                storage = currentPlayer.Inventory.Troop;
                size    = dataController.Get <TroopTypeVO>(contract.ProductUid).Size;
                return;
            }
        }
Пример #3
0
        private void Initializing()
        {
            Logger.Debug("Inventory Actor Initializing ....");
            Self.Tell(new InitializeInventoriesFromStorageMessage());
            ReceiveAsync <InitializeInventoriesFromStorageMessage>(async message =>
            {
                var inventoryIdsResult = await InventoryStorage.ReadAllInventoryIdAsync();

                if (inventoryIdsResult.IsSuccessful)
                {
                    Become(Processing);
                    foreach (var s in inventoryIdsResult.Result)
                    {
                        Logger.Debug("Initializing asking " + s + " for its inventory ....");
                        var invActorRef = GetActorRef(InventoryStorage, s, PerformanceService);
                        invActorRef.Tell(new GetInventoryMessage(s));
                    }
                }
                else
                {
                    var errorMsg = "Failed to read inventories from storage " + InventoryStorage.GetType().FullName + " - " + inventoryIdsResult.Errors.Flatten().Message;
                    Logger.Error("Inventory Actor Initialization Failed " + errorMsg);
                    throw new Exception(errorMsg, inventoryIdsResult.Errors.Flatten());
                }
            });
        }
Пример #4
0
        public static void UpgradeTroopsOrStarshipsInventory(InventoryStorage storage, bool isStarship, string productUpgradeGroup, string productUid)
        {
            IDataController dataController = Service.Get <IDataController>();
            Dictionary <string, InventoryEntry> internalStorage = storage.GetInternalStorage();
            int num = 0;

            foreach (string current in internalStorage.Keys)
            {
                IUpgradeableVO arg_43_0;
                if (!isStarship)
                {
                    IUpgradeableVO upgradeableVO = dataController.Get <TroopTypeVO>(current);
                    arg_43_0 = upgradeableVO;
                }
                else
                {
                    IUpgradeableVO upgradeableVO = dataController.Get <SpecialAttackTypeVO>(current);
                    arg_43_0 = upgradeableVO;
                }
                IUpgradeableVO upgradeableVO2 = arg_43_0;
                if (upgradeableVO2.UpgradeGroup == productUpgradeGroup)
                {
                    num += internalStorage[current].Amount;
                    storage.ClearItemAmount(current);
                }
            }
            storage.ModifyItemAmount(productUid, num);
        }
Пример #5
0
        private IInventoryStorage _storage; // per-user specific storage reference

        public InventoryAPI(ArgvConfigSource options)
        {
            options.AddSwitch("Inventory", "local", "l");
            string useLocal = options.Configs["Inventory"].Get("local");

            if (useLocal != null)   // any value include "" will do
            {
                _cluster    = Properties.LocalSettings.Default.cassandraCluster;
                _connstring = Properties.LocalSettings.Default.coreConnStr;
                m_log.Warn("Using LOCAL settings.");
            }


            try
            {
                _cassandraStorage = new InventoryStorage(_cluster);
                _legacy           = new LegacyMysqlInventoryStorage(_connstring);
                _selector         = new CassandraMigrationProviderSelector(true, _connstring, _cassandraStorage, _legacy);
                m_log.InfoFormat("Cassandra support on '{0}' enabled and ready.", _cluster);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("Unable to connect to cassandra cluster: {0}", e);
            }
        }
Пример #6
0
        private static void AddSpecialAttackProjectileAssets(InventoryStorage storage, List <IAssetVO> assets, IDataController dc)
        {
            Dictionary <string, InventoryEntry> internalStorage = storage.GetInternalStorage();

            foreach (KeyValuePair <string, InventoryEntry> current in internalStorage)
            {
                ProjectileUtils.AddSpecialAttackProjectileAssets(current.get_Key(), assets, dc);
            }
        }
Пример #7
0
        public void AddChampionToInventoryIfAlive(string championUid)
        {
            InventoryStorage champion = base.Inventory.Champion;

            if (champion.GetItemCapacity(championUid) != 0)
            {
                champion.ModifyItemAmount(championUid, 1 - champion.GetItemAmount(championUid));
            }
        }
Пример #8
0
        private static void AddDeployablesToList <T>(InventoryStorage storage, List <IAssetVO> assets, List <string> equipment, StaticDataController dc, SkinController skinController) where T : IValueObject
        {
            Dictionary <string, InventoryEntry> internalStorage = storage.GetInternalStorage();

            foreach (KeyValuePair <string, InventoryEntry> current in internalStorage)
            {
                MapDataLoaderUtils.AddDeployableToList <T>(current.Key, current.Value.Amount, assets, equipment, dc, skinController);
            }
        }
Пример #9
0
        public CassandraMigrationProviderSelector(bool migrationActive,
                                                  string coreConnString,
                                                  InventoryStorage cassandraStorage, LegacyMysqlInventoryStorage legacyStorage)
        {
            _migrationActive  = migrationActive;
            _cassandraStorage = cassandraStorage;
            _legacyStorage    = legacyStorage;

            _checkedCassandraStorage = new CheckedInventoryStorage(_cassandraStorage);
            _checkedLegacyStorage    = new CheckedInventoryStorage(_legacyStorage);
            _migrationStatusChecker  = new MigrationStatusReader(coreConnString);
        }
Пример #10
0
 public Location(Guid guid, string name, Area area, int x, int y, int width, int length, bool home)
 {
     _guid     = guid;
     _name     = name;
     _x        = x;
     _y        = y;
     _width    = width;
     _length   = length;
     _area     = area;
     _home     = home;
     Inventory = new InventoryStorage();
 }
Пример #11
0
    public bool Add(Item item, int amount)
    {
        if (!item.isDefaultItem)
        {
            if (currentSpace - amount >= 0)
            {
                bool found = false;
                bool aaa   = false;
                foreach (InventoryStorage ISD in inventory.ToArray())
                {
                    if (ISD.ID == item.ID)
                    {
                        found         = true;
                        ISD.quantity += amount;
                        Debug.Log("111");
                        stacked               = true;
                        item.quantity         = ISD.quantity;
                        qqq                   = item.quantity;
                        InventorySlot.updateS = true;
                        qqqq.Add(1);
                        Debug.Log(qqqq.Count + "count");
                    }
                }



                if (!found)
                {
                    items.Add(item);
                    InventoryStorage IS = new InventoryStorage(item.ID, item, amount, item.icon);
                    inventory.Add(IS);
                    item.quantity = 1;
                    qqqq.Add(1);
                    currentSpace -= amount;
                    qqq           = 1;
                    if (onItemChangedCallback != null)
                    {
                        onItemChangedCallback.Invoke();
                    }

                    return(true);
                }
                else
                {
                    Debug.Log("Not enough room");
                    return(false);
                }
            }
        }

        return(true);
    }
Пример #12
0
        private void RemoveDeployable(string uid, InventoryStorage storage, int delta)
        {
            int deployableCount = GameUtils.GetDeployableCount(uid, storage);

            if (deployableCount - delta < 0)
            {
                delta = deployableCount;
                Service.Logger.WarnFormat("Can not set a deployable count less than zero. uid: {0}, amount{1}, delta: {2}", new object[]
                {
                    uid,
                    deployableCount,
                    delta
                });
            }
            storage.ModifyItemAmount(uid, -delta);
        }
Пример #13
0
 public PersonModel(Guid guid, string name, Location currentLocation)
 {
     _guid            = guid;
     _name            = name;
     _age             = 0;
     _traits          = new List <PersonTrait>();
     _currentLocation = currentLocation;
     _currentArea     = null;
     TargetLocation   = null;
     _owns            = new List <Location>();
     _currentState    = new DoNothingState();
     Tiredness        = 0;
     Hunger           = 0;
     Inventory        = new InventoryStorage();
     X = currentLocation.X;
     Y = currentLocation.Y;
 }
Пример #14
0
        public void handleCombatMenuEvent(CombatMenu.CombatMenuItem combatMenuItem)
        {
            // The current player has picked an action.  Tell the handler this action is complete.
            menuChoice = combatMenuItem;

            if (menuChoice == CombatMenu.CombatMenuItem.Attack)
            {
                // Find the weapon that was selected
                Player           player    = CurrentPlayer;
                InventoryStorage inventory = player.MyInventory;
                if (inventory != null)
                {
                    player.MyWeapon = inventory.getWeapon("pistol");
                }
            }

            combatActionHandler.handleActionComplete(actionType);
        }
Пример #15
0
        public void Initialize(ConfigSettings settings)
        {
            AquilesHelper.Initialize();
            _storage = new InventoryStorage(settings.InventoryCluster);

            _delayedMutationMgr = new DelayedMutationManager();
            _delayedMutationMgr.Start();
            _storage.DelayedMutationMgr = _delayedMutationMgr;

            if (settings.InventoryMigrationActive)
            {
                _legacyStorage = new LegacyMysqlInventoryStorage(settings.LegacyInventorySource);
            }

            _storageSelector = new CassandraMigrationProviderSelector(settings.InventoryMigrationActive, settings.CoreConnectionString,
                                                                      _storage, _legacyStorage);

            ProviderRegistry.Instance.RegisterInterface <IInventoryProviderSelector>(_storageSelector);
        }
        private GroupLoader()
        {
            var dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            IniConfigSource config   = new IniConfigSource(System.IO.Path.Combine(dir, "Halcyon.ini"));
            var             settings = new ConfigSettings();

            settings.SettingsFile = config.Configs;

            Data.Assets.Stratus.Config.Settings.Instance.DisableWritebackCache = true;
            _stratus = new Data.Assets.Stratus.StratusAssetClient();
            _stratus.Initialize(settings);
            _stratus.Start();

            _legacyInv   = new LegacyMysqlInventoryStorage(Properties.Settings.Default.CoreConnStr);
            _inv         = new InventoryStorage(Properties.Settings.Default.InventoryCluster);
            _invSelector = new CassandraMigrationProviderSelector(Properties.Settings.Default.MigrationActive,
                                                                  Properties.Settings.Default.CoreConnStr, _inv, _legacyInv);
        }
Пример #17
0
        private bool SetDeployableCount(string uid, int amount, InventoryStorage storage, int size)
        {
            if (amount < 0)
            {
                Service.Logger.Debug("Cannot set a deployable count less than zero. uid: " + uid);
                return(false);
            }
            int num = storage.GetTotalStorageAmount() + amount * size;

            if (num > storage.GetTotalStorageCapacity())
            {
                Service.Logger.Debug("Not enough capacity for deployable. uid: " + uid);
                return(false);
            }
            int delta = amount - storage.GetItemAmount(uid);

            storage.ModifyItemAmount(uid, delta);
            return(true);
        }
Пример #18
0
        public void RemoveChampionFromInventory(string championUid)
        {
            InventoryStorage champion = base.Inventory.Champion;

            champion.ModifyItemAmount(championUid, -champion.GetItemAmount(championUid));
        }
Пример #19
0
        public void CreateCharacterProcess(ClientConnection connection, CharacterData info)
        {
            var characterData = info;

            using (var db = _gsDbFactory.OpenSession())
            {
                if (db.QueryOver <CharacterData>().Where(s => s.CharacterName == info.CharacterName).Take(1).SingleOrDefault() != null)
                {
                    new SMSG_CreateCharacterToFieldNak().Send(connection);

                    return;
                }

                using (var transaction = db.BeginTransaction())
                {
                    try
                    {
                        characterData.CharacterId  = _characterUidsFactory.Next();
                        characterData.Surname      = connection.Account.FamilyName;
                        characterData.Level        = 1;
                        characterData.CreationDate = DateTime.Now;
                        characterData.CreatedId    = 0; // for nhibernate driver

                        /* TEMP FIX UNTIL DATA IS FOUND AND LOADED */
                        switch (characterData.ClassType)
                        {
                        case ClassType.Warrior:
                            characterData.PositionX = -153728;
                            characterData.PositionY = 531;
                            characterData.PositionZ = 130574;
                            break;

                        case ClassType.Ranger:
                            characterData.PositionX = -138793;
                            characterData.PositionY = -1208;
                            characterData.PositionZ = 137342;
                            break;

                        case ClassType.Sorcerer:
                            characterData.PositionX = -135621;
                            characterData.PositionY = 802;
                            characterData.PositionZ = 107359;
                            break;

                        case ClassType.Giant:
                            characterData.PositionX = -120118;
                            characterData.PositionY = -1625;
                            characterData.PositionZ = 118794;
                            break;

                        case ClassType.Tamer:
                            characterData.PositionX = -159853;
                            characterData.PositionY = 2089;
                            characterData.PositionZ = 123726;
                            break;

                        case ClassType.BladeMaster:
                            characterData.PositionX = -154408;
                            characterData.PositionY = -335;
                            characterData.PositionZ = 135204;
                            break;

                        case ClassType.BladeMasterWomen:
                            characterData.PositionX = -154408;
                            characterData.PositionY = -335;
                            characterData.PositionZ = 135204;
                            break;

                        case ClassType.Valkyrie:
                            characterData.PositionX = -145479;
                            characterData.PositionY = 2185;
                            characterData.PositionZ = 110947;
                            break;

                        case ClassType.Kunoichi:
                            characterData.PositionX = -136152;
                            characterData.PositionY = -730;
                            characterData.PositionZ = 128869;
                            break;

                        case ClassType.Ninja:
                            characterData.PositionX = -136152;
                            characterData.PositionY = -730;
                            characterData.PositionZ = 128869;
                            break;

                        case ClassType.Wizard:
                            characterData.PositionX = -157013;
                            characterData.PositionY = 946;
                            characterData.PositionZ = 128052;
                            break;

                        case ClassType.WizardWomen:
                            characterData.PositionX = -157013;
                            characterData.PositionY = 946;
                            characterData.PositionZ = 128052;
                            break;
                        }

                        var inventory = InventoryStorage.GetDefault(characterData.ClassType);
                        foreach (var daoItem in inventory.Items.Select(item => new CharacterItem
                        {
                            CharacterId = characterData.CharacterId,
                            ItemId = item.Value.ItemId,
                            ItemUid = _itemsUidsFactory.Next(),
                            Slot = item.Key - 1,
                            Count = item.Value.Count,
                            StorageType = (int)((InventoryItem)item.Value).StorageType
                        }))
                        {
                            db.Save(daoItem);
                        }

                        db.Save(characterData);

                        connection.Characters.Add(characterData);

                        new SMSG_CreateCharacterToField(characterData).Send(connection, false);

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Log.Error($"Cannot create character\n{ex}");
                    }
                }
            }
        }
Пример #20
0
        private Player createPlayerFromTemplate(string referenceName)
        {
            Player player = null;

            if (playersDocument == null)
            {
                this.playersDocument = new XmlDocument();
                playersDocument.Load("Content/Xml/players.xml");
            }

            // Check to see if the player template is in our cache already.
            Player cachedPlayer = lhg.Assets.findPlayerTemplateInCache(referenceName);

            if (cachedPlayer != null)
            {
                progress.updateProgress("Loading player template " + referenceName + " from cache", "Loading", 0);
                return(createQuickCopy(cachedPlayer));
            }
            else
            {
                progress.updateProgress("Loading player template " + referenceName + " from disk", "Loading", 0);
                string  xpath      = "/players/player[@referenceName='" + referenceName + "']";
                XmlNode playerNode = playersDocument.SelectSingleNode(xpath);
                if (playerNode != null)
                {
                    PrimaryStatistics stats = null;

                    List <PlayerSpriteSheet> playerSpriteSheetList = null;
                    StaticSprite             hudSprite             = null;
                    InventoryStorage         inventoryStorage      = null;
                    Player.Type type           = Player.getTypeFromString(playerNode.Attributes["type"].Value);
                    XmlNodeList playerChildren = playerNode.ChildNodes;
                    foreach (XmlNode childNode in playerChildren)
                    {
                        switch (childNode.Name)
                        {
                        case "stats":
                            stats = loadStats(childNode);
                            break;

                        case "hud":
                            hudSprite = loadCombatHUDSprite(childNode);
                            break;

                        case "animations":
                            playerSpriteSheetList = loadAnimations(childNode);
                            break;

                        case "inventory":
                            inventoryStorage = loadInventory(childNode);
                            break;
                        }
                    }

                    PlayerSprite playerSprite = new PlayerSprite(lhg, playerSpriteSheetList, PlayerSpriteSheet.Type.Standing);

                    // Create a player for our cache that won't change, so we can quickly create copies
                    if (type == Player.Type.Human)
                    {
                        cachedPlayer = new Human(lhg, referenceName, referenceName, playerSprite);
                    }
                    else if (type == Player.Type.Zombie)
                    {
                        cachedPlayer = new Zombie(lhg, referenceName, referenceName, playerSprite);
                    }

                    cachedPlayer.MyHUDSprite = hudSprite;
                    cachedPlayer.MyInventory = inventoryStorage;
                    lhg.Assets.addPlayerTemplate(cachedPlayer);

                    // Now, create a copy we will use as the real instance
                    player = createQuickCopy(cachedPlayer);
                }
            }

            return(player);
        }
Пример #21
0
        public static int TransferPrizeFromInventory(PrizeType prizeType, string prizeID)
        {
            Lang             lang               = Service.Get <Lang>();
            IDataController  dataController     = Service.Get <IDataController>();
            CurrentPlayer    currentPlayer      = Service.Get <CurrentPlayer>();
            PrizeInventory   prizes             = currentPlayer.Prizes;
            Inventory        inventory          = currentPlayer.Inventory;
            InventoryStorage inventoryStorage   = null;
            IUpgradeableVO   finalUnitFromPrize = TimedEventPrizeUtils.GetFinalUnitFromPrize(prizeType, prizeID);
            string           text               = null;
            string           text2              = null;
            string           id = null;
            int result          = 0;
            int num             = 0;

            switch (prizeType)
            {
            case PrizeType.Currency:
                num = prizes.GetResourceAmount(prizeID);
                TimedEventPrizeUtils.GetCurrencyAmountToTransfer(prizeID, ref num, ref result);
                if (num > 0)
                {
                    inventory.ModifyItemAmount(prizeID, num);
                    prizes.ModifyResourceAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_CURRENCY";
                    text2 = lang.Get(prizeID.ToUpper(), new object[0]);
                }
                else
                {
                    id = "INVENTORY_NO_ROOM";
                }
                break;

            case PrizeType.Infantry:
            case PrizeType.Vehicle:
            case PrizeType.Mercenary:
                inventoryStorage = inventory.Troop;
                if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    num = 1;
                    inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                    prizes.ModifyTroopAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_TROOP";
                    text2 = LangUtils.GetTroopDisplayName((TroopTypeVO)finalUnitFromPrize);
                    StorageSpreadUtils.UpdateAllStarportFullnessMeters();
                }
                else
                {
                    id = "NOT_ENOUGH_HOUSING";
                }
                result = prizes.GetTroopAmount(prizeID);
                break;

            case PrizeType.Hero:
                inventoryStorage = inventory.Hero;
                if (!Service.Get <BuildingLookupController>().HasHeroCommand())
                {
                    id = "INVENTORY_NO_HERO_COMMAND";
                }
                else if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    bool flag = false;
                    foreach (KeyValuePair <string, InventoryEntry> current in inventoryStorage.GetInternalStorage())
                    {
                        if (current.get_Value().Amount > 0)
                        {
                            TroopTypeVO troopTypeVO = dataController.Get <TroopTypeVO>(current.get_Key());
                            if (troopTypeVO.UpgradeGroup == finalUnitFromPrize.UpgradeGroup)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        flag = ContractUtils.HasExistingHeroContract(finalUnitFromPrize.UpgradeGroup);
                    }
                    if (!flag)
                    {
                        num = 1;
                        inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                        prizes.ModifyTroopAmount(prizeID, -num);
                        text  = "INVENTORY_REWARD_USED_HERO";
                        text2 = LangUtils.GetTroopDisplayName((TroopTypeVO)finalUnitFromPrize);
                        Service.Get <EventManager>().SendEvent(EventId.HeroMobilizedFromPrize, finalUnitFromPrize.Uid);
                    }
                    else
                    {
                        id = "INVENTORY_NO_ROOM_HERO_IN_QUEUE";
                    }
                }
                else
                {
                    id = "INVENTORY_NO_ROOM_HERO";
                }
                result = prizes.GetTroopAmount(prizeID);
                break;

            case PrizeType.SpecialAttack:
                inventoryStorage = inventory.SpecialAttack;
                if (!Service.Get <BuildingLookupController>().HasStarshipCommand())
                {
                    id = "INVENTORY_NO_FLEET_COMMAND";
                }
                else if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    num = 1;
                    inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                    prizes.ModifySpecialAttackAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_TROOP";
                    text2 = LangUtils.GetStarshipDisplayName((SpecialAttackTypeVO)finalUnitFromPrize);
                    Service.Get <EventManager>().SendEvent(EventId.StarshipMobilizedFromPrize, finalUnitFromPrize.Uid);
                }
                else
                {
                    id = "NOT_ENOUGH_SPACE";
                }
                result = prizes.GetSpecialAttackAmount(prizeID);
                break;
            }
            if (num > 0)
            {
                InventoryTransferRequest request = new InventoryTransferRequest(prizeID, num);
                Service.Get <ServerAPI>().Enqueue(new InventoryTransferCommand(request));
            }
            else
            {
                string message = lang.Get(id, new object[0]);
                AlertScreen.ShowModal(false, null, message, null, null);
            }
            if (text != null)
            {
                string text3 = (prizeType == PrizeType.Hero) ? text2 : lang.Get("AMOUNT_AND_NAME", new object[]
                {
                    num,
                    text2
                });
                string instructions = lang.Get(text, new object[]
                {
                    text3
                });
                Service.Get <UXController>().MiscElementsManager.ShowPlayerInstructions(instructions, 1f, 2f);
            }
            return(result);
        }