コード例 #1
0
        public static List <object> SerializeAttributes(GameEntity itemEntity, SenseType sense, SerializationContext context)
        {
            var canIdentify = itemEntity != null && sense.CanIdentify();

            if (!canIdentify)
            {
                return(new List <object>());
            }

            var manager        = itemEntity.Manager;
            var item           = itemEntity.Item;
            var template       = Item.Loader.Get(item.TemplateName);
            var physical       = itemEntity.Physical;
            var equipableSlots = manager.ItemUsageSystem.GetEquipableSlots(item, context.Observer.Physical.Size)
                                 .GetNonRedundantFlags(removeComposites: true)
                                 .Select(s => Serialize(s, context))
                                 .ToList();

            return(new List <object>(13)
            {
                context.Services.Language.GetString(item, item.GetQuantity(manager), sense),
                context.Services.Language.GetDescription(item.TemplateName, DescriptionCategory.Item),
                item.Type,
                (int)physical.Material,
                physical.Size,
                physical.Weight,
                item.Hindrance,
                template.Complexity,
                template.RequiredMight,
                template.RequiredSpeed,
                template.RequiredFocus,
                template.RequiredPerception,
                equipableSlots,
                manager.AbilitiesToAffectableRelationship[itemEntity.Id]
                .Where(a => a.Ability.IsUsable &&
                       a.Ability.Activation != ActivationType.Default &&
                       a.Ability.Activation != ActivationType.Always &&
                       a.Ability.Activation != ActivationType.WhilePossessed)
                .Select(a => AbilitySnapshot.SerializeAttributes(a, context.Observer, context)).ToList()
            });
        }
コード例 #2
0
ファイル: GameHub.cs プロジェクト: attackgithub/UnicornHack
        public List <object> QueryGame(string playerName, int intQueryType, int[] arguments)
        {
            var queryType = (GameQueryType)intQueryType;
            var result    = new List <object> {
                intQueryType
            };

            var player = FindPlayer(playerName);

            if (player?.Entity.Being.IsAlive != true)
            {
                return(result);
            }

            var manager = player.Entity.Manager;
            var context = new SerializationContext(_dbContext, player.Entity, _gameServices);

            switch (queryType)
            {
            case GameQueryType.SlottableAbilities:
                var slot = arguments[0];
                result.Add(slot);
                var abilities = new List <object>();
                result.Add(abilities);

                foreach (var slottableAbilityEntity in manager.AbilitiesToAffectableRelationship[player.EntityId])
                {
                    var ability = slottableAbilityEntity.Ability;
                    if (!ability.IsUsable)
                    {
                        continue;
                    }

                    if (slot == AbilitySlottingSystem.DefaultMeleeAttackSlot)
                    {
                        if (ability.Template?.Type == AbilityType.DefaultAttack &&
                            ((WieldingAbility)ability.Template).ItemType == ItemType.WeaponMelee)
                        {
                            abilities.Add(AbilitySnapshot.Serialize(slottableAbilityEntity, null, context));
                        }
                    }
                    else if (slot == AbilitySlottingSystem.DefaultRangedAttackSlot)
                    {
                        if (ability.Template?.Type == AbilityType.DefaultAttack &&
                            ((WieldingAbility)ability.Template).ItemType == ItemType.WeaponRanged)
                        {
                            abilities.Add(AbilitySnapshot.Serialize(slottableAbilityEntity, null, context));
                        }
                    }
                    else if ((ability.Activation & ActivationType.Slottable) != 0 &&
                             ability.Template?.Type != AbilityType.DefaultAttack)
                    {
                        abilities.Add(AbilitySnapshot.Serialize(slottableAbilityEntity, null, context));
                    }
                }

                break;

            case GameQueryType.PlayerAttributes:
                result.Add(LevelActorSnapshot.SerializeAttributes(player.Entity, SenseType.Sight, context));
                break;

            case GameQueryType.PlayerAdaptations:
                result.Add(PlayerSnapshot.SerializeAdaptations(player.Entity, context));
                break;

            case GameQueryType.PlayerSkills:
                result.Add(PlayerSnapshot.SerializeSkills(player.Entity, context));
                break;

            case GameQueryType.ActorAttributes:
                var actorKnowledge = manager.FindEntity(arguments[0])?.Knowledge;

                result.Add(LevelActorSnapshot.SerializeAttributes(
                               actorKnowledge?.KnownEntity, actorKnowledge?.SensedType ?? SenseType.None, context));
                break;

            case GameQueryType.ItemAttributes:
                var itemEntity    = manager.FindEntity(arguments[0]);
                var item          = itemEntity?.Item;
                var itemKnowledge = itemEntity?.Knowledge;

                if (item != null)
                {
                    result.Add(InventoryItemSnapshot.SerializeAttributes(itemEntity, SenseType.Sight, context));
                }
                else
                {
                    result.Add(InventoryItemSnapshot.SerializeAttributes(
                                   itemKnowledge?.KnownEntity, itemKnowledge?.SensedType ?? SenseType.None, context));
                }

                break;

            case GameQueryType.AbilityAttributes:
                var abilityEntity = manager.FindEntity(arguments[0]);

                var ownerEntity     = abilityEntity.Ability.OwnerEntity;
                var activatorEntity = abilityEntity.Ability.OwnerEntity.HasComponent(EntityComponent.Item)
                        ? player.Entity
                        : ownerEntity;

                result.Add(AbilitySnapshot.SerializeAttributes(abilityEntity, activatorEntity, context));
                break;

            default:
                throw new InvalidOperationException($"Query type {intQueryType} not supported");
            }

            return(result);
        }
コード例 #3
0
        public static List <object> SerializeAttributes(GameEntity actorEntity, SenseType sense, SerializationContext context)
        {
            var canIdentify = actorEntity != null && sense.CanIdentify();

            if (!canIdentify)
            {
                return(new List <object>());
            }

            var being       = actorEntity.Being;
            var sensor      = actorEntity.Sensor;
            var physical    = actorEntity.Physical;
            var description = actorEntity.HasComponent(EntityComponent.Player)
                ? ""
                : context.Services.Language.GetDescription(
                actorEntity.Manager.RacesToBeingRelationship[actorEntity.Id].Values.First().Race.TemplateName,
                DescriptionCategory.Creature);
            var result = new List <object>(40)
            {
                context.Services.Language.GetActorName(actorEntity, sense),
                description,
                actorEntity.Position.MovementDelay,
                physical.Size,
                physical.Weight,
                sensor.PrimaryFOVQuadrants,
                sensor.PrimaryVisionRange,
                sensor.TotalFOVQuadrants,
                sensor.SecondaryVisionRange,
                sensor.Infravision,
                sensor.InvisibilityDetection,
                physical.Infravisible,
                being.Visibility,
                being.HitPoints,
                being.HitPointMaximum,
                being.EnergyPoints,
                being.EnergyPointMaximum,
                being.Might,
                being.Speed,
                being.Focus,
                being.Perception,
                being.Regeneration,
                being.EnergyRegeneration,
                being.Armor,
                being.Deflection,
                being.Evasion,
                being.PhysicalResistance,
                being.MagicResistance,
                being.BleedingResistance,
                being.AcidResistance,
                being.ColdResistance,
                being.ElectricityResistance,
                being.FireResistance,
                being.PsychicResistance,
                being.ToxinResistance,
                being.VoidResistance,
                being.SonicResistance,
                being.StunResistance,
                being.LightResistance,
                being.WaterResistance
            };

            if (!actorEntity.HasComponent(EntityComponent.Player))
            {
                result.Add(actorEntity.Manager.AbilitiesToAffectableRelationship[actorEntity.Id]
                           .Where(a => a.Ability.IsUsable &&
                                  a.Ability.Activation != ActivationType.Default &&
                                  a.Ability.Activation != ActivationType.Always &&
                                  a.Ability.Activation != ActivationType.OnMeleeAttack &&
                                  a.Ability.Activation != ActivationType.OnRangedAttack)  // Instead add the effects to the corresponding abilities
                           .Select(a => AbilitySnapshot.SerializeAttributes(a, actorEntity, context)).ToList());
            }

            return(result);
        }