Exemplo n.º 1
0
        public async Task MoveItemsBetweenInventoriesAsync(Item item, Lot lot, uint count, InventoryType source, InventoryType destination, bool silent = false)
        {
            if (item?.Settings != null)
            {
                if (count != 1 || item.Count != 1)
                {
                    Logger.Error($"Invalid special item {item}");
                    return;
                }

                Destroy(item);

                await AddItemAsync(item.Lot, count, destination, item.Settings);

                return;
            }

            RemoveItem(item?.Lot ?? lot, count, source, silent);

            await AddItemAsync(item?.Lot ?? lot, count, destination);
        }
Exemplo n.º 2
0
        public async Task RemoveItemAsync(Lot lot, uint count, bool silent = false)
        {
            if (count == default)
            {
                return;
            }

            await using var cdClient = new CdClientContext();

            var componentId = await cdClient.ComponentsRegistryTable.FirstOrDefaultAsync(
                r => r.Id == lot && r.Componenttype == (int)ComponentId.ItemComponent
                );

            if (componentId == default)
            {
                Logger.Error($"{lot} does not have a Item component");
                return;
            }

            var component = await cdClient.ItemComponentTable.FirstOrDefaultAsync(
                i => i.Id == componentId.Componentid
                );

            if (component == default)
            {
                Logger.Error(
                    $"{lot} has a corrupted component registry. There is no Item component of Id: {componentId.Componentid}"
                    );

                return;
            }

            Debug.Assert(component.ItemType != null, "component.ItemType != null");

            RemoveItem(lot, count, ((ItemType)component.ItemType).GetInventoryType(), silent);
        }
Exemplo n.º 3
0
 public Item FindItem(Lot lot, InventoryType inventoryType)
 {
     return(_inventories[inventoryType].Items.FirstOrDefault(i => i.Lot == lot));
 }
Exemplo n.º 4
0
 public Item FindItem(Lot lot)
 {
     return(_inventories.Values.Select(
                inventory => inventory.Items.FirstOrDefault(i => i.Lot == lot)
                ).FirstOrDefault(item => item != default));
 }
Exemplo n.º 5
0
 public Item[] FindItems(Lot lot, InventoryType inventoryType)
 {
     return(_inventories[inventoryType].Items.Where(i => i.Lot == lot).ToArray());
 }
Exemplo n.º 6
0
 public Item[] FindItems(Lot lot)
 {
     return(_inventories.Values.SelectMany(
                inventory => inventory.Items.Where(i => i.Lot == lot)
                ).ToArray());
 }
Exemplo n.º 7
0
        public bool TryFindItem(Lot lot, InventoryType inventoryType, out Item item)
        {
            item = FindItem(lot, inventoryType);

            return(item != default);
        }
Exemplo n.º 8
0
        public bool TryFindItem(Lot lot, out Item item)
        {
            item = FindItem(lot);

            return(item != default);
        }
Exemplo n.º 9
0
 public Task RemoveAllAsync(Lot lot, bool silent = false)
 {
     return(RemoveItemAsync(lot, CountItems(lot), silent));
 }
Exemplo n.º 10
0
Arquivo: Item.cs Projeto: kulaj/Uchu
        public static Item Instantiate(Lot lot, Inventory inventory, uint count, uint slot, LegoDataDictionary extraInfo = default)
        {
            using var cdClient = new CdClientContext();
            using var ctx      = new UchuContext();

            var cdClientObject = cdClient.ObjectsTable.FirstOrDefault(
                o => o.Id == lot
                );

            var itemRegistryEntry = cdClient.ComponentsRegistryTable.FirstOrDefault(
                r => r.Id == lot && r.Componenttype == 11
                );

            if (cdClientObject == default || itemRegistryEntry == default)
            {
                Logger.Error($"<new item> [{lot}] is not a valid item");
                return(null);
            }

            var instance = Instantiate <Item>
                           (
                inventory.ManagerComponent.Zone, cdClientObject.Name, objectId: ObjectId.Standalone, lot: lot
                           );

            instance.Settings = extraInfo ?? new LegoDataDictionary();

            var itemComponent = cdClient.ItemComponentTable.First(
                i => i.Id == itemRegistryEntry.Componentid
                );

            instance.Inventory = inventory;
            instance.Player    = inventory.ManagerComponent.GameObject as Player;

            var playerCharacter = ctx.Characters.Include(c => c.Items).First(
                c => c.Id == inventory.ManagerComponent.GameObject.Id
                );

            var inventoryItem = new InventoryItem
            {
                Count         = count,
                InventoryType = (int)inventory.InventoryType,
                Id            = instance.Id,
                IsBound       = itemComponent.IsBOP ?? false,
                Slot          = (int)slot,
                Lot           = lot,
                ExtraInfo     = extraInfo?.ToString()
            };

            playerCharacter.Items.Add(inventoryItem);

            ctx.SaveChanges();

            var message = new AddItemToInventoryMessage
            {
                Associate       = inventory.ManagerComponent.GameObject,
                InventoryType   = (int)inventory.InventoryType,
                Delta           = count,
                TotalItems      = count,
                Slot            = (int)slot,
                ItemLot         = lot,
                IsBoundOnEquip  = itemComponent.IsBOE ?? false,
                IsBoundOnPickup = itemComponent.IsBOP ?? false,
                IsBound         = inventoryItem.IsBound,
                Item            = instance,
                ExtraInfo       = extraInfo
            };

            (inventory.ManagerComponent.GameObject as Player)?.Message(message);

            inventory.ManageItem(instance);

            return(instance);
        }
Exemplo n.º 11
0
 public bool HasEquipped(Lot lot)
 {
     return(Items.Any(i => i.Value.Lot == lot));
 }
Exemplo n.º 12
0
 public static GameObject InstantiateLoot(Lot lot, Player owner, GameObject source, Vector3 spawn)
 {
     if (owner is null)
     {
         return(default);
Exemplo n.º 13
0
 public override void Deserialize(BitReader reader)
 {
     Lot = reader.Read <Lot>();
 }
Exemplo n.º 14
0
        // TODO: Improve
        private async Task SearchForNewAchievementsAsync <T>(MissionTaskType type, Lot lot, Func <T, Task> progress = null) where T : MissionTaskBase
        {
            await using var cdClient = new CdClientContext();

            //
            // Collect tasks which fits the requirements of this action.
            //

            var otherTasks = new List <MissionTasks>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var missionTask in cdClient.MissionTasksTable)
            {
                if (MissionParser.GetTargets(missionTask).Contains(lot))
                {
                    otherTasks.Add(missionTask);
                }
            }

            foreach (var task in otherTasks)
            {
                var mission = await cdClient.MissionsTable.FirstOrDefaultAsync(m => m.Id == task.Id);

                if (mission == default)
                {
                    continue;
                }

                //
                // Check if mission is an achievement and has a task of the correct type.
                //

                if (mission.OfferobjectID != -1 ||
                    mission.TargetobjectID != -1 ||
                    (mission.IsMission ?? true) ||
                    task.TaskType != (int)type)
                {
                    continue;
                }

                //
                // Get the mission on the character. If present.
                //

                var characterMission = MissionInstances.FirstOrDefault(m => m.MissionId == mission.Id);

                //
                // Check if the player could passably start this achievement.
                //

                if (characterMission != default)
                {
                    continue;
                }

                //
                // Check if player has the Prerequisites to start this achievement.
                //

                var hasPrerequisites = MissionParser.CheckPrerequiredMissions(
                    mission.PrereqMissionID,
                    GetCompletedMissions()
                    );

                if (!hasPrerequisites)
                {
                    continue;
                }

                //
                // Player can start achievement.
                //

                // Get Mission Id of new achievement.
                if (mission.Id == default)
                {
                    continue;
                }

                var missionId = mission.Id.Value;

                //
                // Setup new achievement.
                //

                var instance = new MissionInstance(GameObject as Player, missionId);

                MissionInstances.Add(instance);

                await instance.LoadAsync();

                // TODO: Silent?
                await instance.StartAsync();

                var activeTask = instance.Tasks.First(t => t.TaskId == task.Uid);

                if (progress != null)
                {
                    Detach(async() =>
                    {
                        await progress(activeTask as T);
                    });
                }
            }
        }
Exemplo n.º 15
0
        private async Task <bool> RequiredForNewAchievementsAsync(MissionTaskType type, Lot lot)
        {
            await using var cdClient = new CdClientContext();

            //
            // Collect tasks which fits the requirements of this action.
            //

            var otherTasks = new List <MissionTasks>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var missionTask in ClientCache.Tasks)
            {
                if (MissionParser.GetTargets(missionTask).Contains(lot))
                {
                    otherTasks.Add(missionTask);
                }
            }

            foreach (var task in otherTasks)
            {
                var mission = await cdClient.MissionsTable.FirstOrDefaultAsync(m => m.Id == task.Id);

                if (mission == default)
                {
                    continue;
                }

                //
                // Check if mission is an achievement and has a task of the correct type.
                //

                if (mission.OfferobjectID != -1 ||
                    mission.TargetobjectID != -1 ||
                    (mission.IsMission ?? true) ||
                    task.TaskType != (int)type)
                {
                    continue;
                }

                //
                // Get the mission on the character. If present.
                //

                MissionInstance characterMission;

                await Lock.WaitAsync();

                try
                {
                    characterMission = MissionInstances.FirstOrDefault(m => m.MissionId == mission.Id);
                }
                finally
                {
                    Lock.Release();
                }

                //
                // Check if the player could passably start this achievement.
                //

                if (characterMission != default)
                {
                    continue;
                }

                //
                // Check if player has the Prerequisites to start this achievement.
                //

                var hasPrerequisites = MissionParser.CheckPrerequiredMissions(
                    mission.PrereqMissionID,
                    GetCompletedMissions()
                    );

                if (hasPrerequisites)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 16
0
        public async Task RespondToMissionAsync(int missionId, GameObject missionGiver, Lot rewardItem)
        {
            //
            // The player has clicked on the accept or complete button.
            //

            await using var ctx      = new UchuContext();
            await using var cdClient = new CdClientContext();

            //
            // Get the mission the player is responding to.
            //

            var mission = MissionInstances.FirstOrDefault(m => m.MissionId == missionId);

            //
            // Check if the player is accepting a mission or responding to one.
            //

            if (mission == default)
            {
                var instance = new MissionInstance(GameObject as Player, missionId);

                MissionInstances.Add(instance);

                await instance.LoadAsync();

                await instance.StartAsync();

                return;
            }

            //
            // Player is responding to an active mission.
            //

            var isComplete = await mission.IsCompleteAsync();

            if (!isComplete)
            {
                //
                // Mission is not complete.
                //

                var currentState = await mission.GetMissionStateAsync();

                await mission.UpdateMissionStateAsync(currentState);

                MessageOfferMission(missionId, missionGiver);

                return;
            }

            //
            // Complete mission.
            //

            await mission.CompleteAsync(rewardItem);

            missionGiver?.GetComponent <MissionGiverComponent>().OfferMission(GameObject as Player);
        }
Exemplo n.º 17
0
 public uint CountItems(Lot lot)
 {
     return((uint)Items.Sum(item => item.Count));
 }