コード例 #1
0
 public string ClassTypeToString(PlayerClassType.ClassList classType)
 {
     string ret = "";
     switch (classType)
     {
         case PlayerClassType.ClassList.GAME_MASTER:
             ret = "Game Master";
             break;
         case PlayerClassType.ClassList.AGILE:
             ret = "Agile";
             break;
         case PlayerClassType.ClassList.BASE_DEFENDER:
             ret = "Base Defender";
             break;
         case PlayerClassType.ClassList.DEFENDER:
             ret = "Defender";
             break;
         case PlayerClassType.ClassList.INDUSTRY:
             ret = "Industry";
             break;
         case PlayerClassType.ClassList.WEAPON_SPECIALIST:
             ret = "Weapon Specialist";
             break;
         case PlayerClassType.ClassList.MERCENERY:
             ret = "Mercenery";
             break;
     }
     return ret;
 }
コード例 #2
0
 /// <summary>
 /// Sets the player's class type
 /// </summary>
 /// <param name="classType">Class type.</param>
 public void SetPlayerClassName(PlayerClassType.ClassList classType)
 {
     switch(classType){
         case PlayerClassType.ClassList.GAME_MASTER:
             SetPlayerClassName("Game Master");
             break;
         case PlayerClassType.ClassList.AGILE:
             SetPlayerClassName("Agile");
             break;
         case PlayerClassType.ClassList.BASE_DEFENDER:
             SetPlayerClassName("Base Defender");
             break;
         case PlayerClassType.ClassList.DEFENDER:
             SetPlayerClassName("Defender");
             break;
         case PlayerClassType.ClassList.INDUSTRY:
             SetPlayerClassName("Industry");
             break;
         case PlayerClassType.ClassList.WEAPON_SPECIALIST:
             SetPlayerClassName("Weapon Specialist");
             break;
         case PlayerClassType.ClassList.MERCENERY:
             SetPlayerClassName("Mercenery");
             break;
     }
 }
コード例 #3
0
 /// <summary>Resets the profile to an uninitialized state with the default player class.</summary>
 private void Reset()
 {
     PlayerClass = PlayerClassType.Default;
     if (_data != null)
     {
         _data.Dispose();
         _data = null;
     }
 }
コード例 #4
0
 public int deriveDefenseValue(PlayerClassType.ClassList calculateClass, int experienceValue)
 {
     int defenseValue = 0;
     switch (calculateClass)
     {
         case PlayerClassType.ClassList.AGILE:
             defenseValue = experienceValue;
             break;
     }
     return defenseValue;
 }
コード例 #5
0
    public void UpdateRules(PlayerClassType currentPlayerClass)
    {
        playerClassType.Set(currentPlayerClass);

        if (playerClassType.ClearDirty())
        {
            foreach (ContextRulePlayerClass rule in playerClassRules)
            {
                rule.CurrentPlayerClass = currentPlayerClass;
                ruleUpdater.DirtyRule(rule);
            }
        }
    }
コード例 #6
0
ファイル: Automater.cs プロジェクト: dtabacaru/MindControl
        private static void CheckClass()
        {
            if (Api.PlayerData.Found && m_CurrentClass != Api.PlayerData.Class)
            {
                m_CurrentClass = Api.PlayerData.Class;
                switch (Api.PlayerData.Class)
                {
                case PlayerClassType.Warrior:
                    m_WowClassAutomater = Warrior;
                    break;

                case PlayerClassType.Paladin:
                    m_WowClassAutomater = Paladin;
                    break;

                case PlayerClassType.Rogue:
                    m_WowClassAutomater = Rogue;
                    break;

                case PlayerClassType.Priest:
                    m_WowClassAutomater = Priest;
                    break;

                case PlayerClassType.Mage:
                    m_WowClassAutomater = Mage;
                    break;

                case PlayerClassType.Warlock:
                    m_WowClassAutomater = Warlock;
                    break;

                case PlayerClassType.Hunter:
                    m_WowClassAutomater = Hunter;
                    break;

                case PlayerClassType.Shaman:
                    m_WowClassAutomater = Shaman;
                    break;

                case PlayerClassType.Druid:
                    m_WowClassAutomater = Druid;
                    break;

                default:
                    break;
                }
            }
        }
コード例 #7
0
ファイル: EntityFactory.cs プロジェクト: matrix4x4/Space
        /// <summary>Creates a new, player controlled ship.</summary>
        /// <param name="manager">The manager.</param>
        /// <param name="playerClass">The player's class, which determines the blueprint.</param>
        /// <param name="playerNumber">The player for whom to create the ship.</param>
        /// <param name="position">The position at which to spawn and respawn the ship.</param>
        /// <returns>The new ship.</returns>
        public static int CreatePlayerShip(
            IManager manager, PlayerClassType playerClass, int playerNumber, FarPosition position)
        {
            // Player ships must be 'static', i.e. not have random attributes, so we don't need a randomizer.
            var entity = FactoryLibrary.SampleShip(
                manager, playerClass.GetShipFactoryName(), playerNumber.ToFaction(), position, null);

            // Remember the class.
            manager.AddComponent <PlayerClass>(entity).Initialize(playerClass);

            // Mark it as the player's avatar.
            manager.AddComponent <Avatar>(entity).Initialize(playerNumber);

            // Make it respawn (after 5 seconds).
            manager.AddComponent <Respawn>(entity).Initialize(
                (int)(5 * Settings.TicksPerSecond),
                new HashSet <Type>
            {
                // Make ship uncontrollable.
                typeof(ShipControl),
                typeof(WeaponControl),
                // Disable collisions.
                typeof(Body),
                // And movement.
                typeof(Gravitation),
                // Hide it.
                typeof(ShipDrawable),
                typeof(ParticleEffects),
                // And don't regenerate.
                typeof(Health),
                typeof(Energy)
            },
                position);

            // Allow leveling up.
            manager.AddComponent <Experience>(entity).Initialize(100, 100f, 2.15f);

            // Make player ships collide more precisely. We don't much care for NPC ships tunneling
            // through stuff (unlikely as that may be anyways), but we really don't want it to happen
            // for a player ship.
            var body = (Body)manager.GetComponent(entity, Body.TypeId);

            body.IsBullet = true;

            return(entity);
        }
コード例 #8
0
        /// <summary>Creates a new profile with the specified name and the specified player class.</summary>
        /// <param name="name">The name of the profile.</param>
        /// <param name="playerClass">The player class.</param>
        /// <exception cref="ArgumentException">profile name is invalid.</exception>
        public void Create(string name, PlayerClassType playerClass)
        {
            if (InvalidCharPattern.IsMatch(name))
            {
                throw new ArgumentException(@"Invalid profile name, contains invalid character.", "name");
            }

            // Save name and class, initialization will be done when restore
            // is called for the first time.
            Reset();
            Name        = name;
            PlayerClass = playerClass;

            if (File.Exists(GetFullProfilePath()))
            {
                Logger.Warn("Profile with that name already exists.");
            }
        }
コード例 #9
0
    public PlayerSaveData(Player player)
    {
        playerName = player.entityName;

        currentHealth = player.Health.currentHealth;
        baseHP        = player.Health.baseHP;

        classType = player.playerClass.classType;
        Debug.Log("Saving player with Data " + classType);
        playerLevel      = player.playerLevel;
        playerExperience = player.playerExperience;

        talents = new List <TalentSaveData>();

        foreach (Talent talent in player.talentTree.GetAllTalents())
        {
            if (talent.isLearned)
            {
                Debug.Log("Saving Talent " + talent.talentName);
                talents.Add(talent.GetSaveData());
            }
        }

        items = new List <ItemSaveData>();

        foreach (InventorySlot slot in player.Inventory.slots)
        {
            if (slot.item != null)
            {
                for (int i = 0; i < slot.amount; i++)
                {
                    ItemSaveData data = slot.item.GetSaveData();
                    items.Add(data);
                }
            }
        }

        colors = new List <SerializableColor>();
        foreach (Color color in ((PlayerRenderer)player.Renderer).colorSwap.mBaseColors)
        {
            colors.Add(color);
        }
    }
コード例 #10
0
ファイル: PlayerClass.cs プロジェクト: matrix4x4/Space
        /// <summary>Initialize with the specified player class.</summary>
        /// <param name="playerClass">The player class.</param>
        public PlayerClass Initialize(PlayerClassType playerClass)
        {
            Value = playerClass;

            return(this);
        }
コード例 #11
0
        public Player(string name, PlayerClassType playerClass)
        {
            Name                  = name;
            PlayerClass           = playerClass;
            StatReplenishInterval = 3;
            Level                 = 1;
            ExperienceToLevel     = Settings.GetBaseExperienceToLevel();
            Inventory             = new List <IItem>();
            Effects               = new List <IEffect>();
            QuestLog              = new List <Quest>();
            FireResistance        = 5;
            FrostResistance       = 5;
            ArcaneResistance      = 5;
            switch (PlayerClass)
            {
            case PlayerClassType.Mage:
                for (int i = 0; i < 3; i++)
                {
                    Inventory.Add(new ManaPotion(PotionStrength.Minor));
                }
                Spellbook            = new List <PlayerSpell>();
                Strength             = 10;
                Dexterity            = 5;
                Intelligence         = 15;
                Constitution         = 10;
                MaxManaPoints        = Intelligence * 10;
                ManaPoints           = MaxManaPoints;
                CanWearCloth         = true;
                CanUseDagger         = true;
                CanUseOneHandedSword = true;
                Inventory.Add(new Weapon(Level, WeaponType.Dagger));
                Inventory.Add(new Armor(
                                  1, ArmorType.Cloth, ArmorSlot.Head));
                Inventory.Add(new Armor(
                                  1, ArmorType.Cloth, ArmorSlot.Chest));
                Inventory.Add(new Armor(
                                  1, ArmorType.Cloth, ArmorSlot.Legs));
                Spellbook.Add(new PlayerSpell(
                                  "fireball", 35, 1, SpellType.Fireball, 1));
                Spellbook.Add(new PlayerSpell(
                                  "heal", 25, 1, SpellType.Heal, 1));
                Spellbook.Add(new PlayerSpell(
                                  "diamondskin", 25, 1, SpellType.Diamondskin, 1));
                Spellbook.Add(new PlayerSpell(
                                  "frostbolt", 25, 1, SpellType.Frostbolt, 1));
                Spellbook.Add(new PlayerSpell(
                                  "lightning", 25, 1, SpellType.Lightning, 1));
                Spellbook.Add(new PlayerSpell(
                                  "rejuvenate", 25, 1, SpellType.Rejuvenate, 1));
                break;

            case PlayerClassType.Warrior:
                for (int i = 0; i < 3; i++)
                {
                    Inventory.Add(new HealthPotion(PotionStrength.Minor));
                }
                Abilities            = new List <PlayerAbility>();
                Strength             = 15;
                Dexterity            = 5;
                Intelligence         = 5;
                Constitution         = 15;
                MaxRagePoints        = Strength * 10;
                RagePoints           = MaxRagePoints;
                CanWearCloth         = true;
                CanWearLeather       = true;
                CanWearPlate         = true;
                CanUseAxe            = true;
                CanUseDagger         = true;
                CanUseBow            = true;
                CanUseOneHandedSword = true;
                CanUseTwoHandedSword = true;
                Inventory.Add(new Weapon(Level, WeaponType.TwoHandedSword));
                Inventory.Add(new Armor(
                                  1, ArmorType.Plate, ArmorSlot.Head));
                Inventory.Add(new Armor(
                                  1, ArmorType.Plate, ArmorSlot.Chest));
                Inventory.Add(new Armor(
                                  1, ArmorType.Plate, ArmorSlot.Legs));
                Abilities.Add(new PlayerAbility(
                                  "charge", 25, 1, WarriorAbility.Charge, 1));
                Abilities.Add(new PlayerAbility(
                                  "slash", 40, 1, WarriorAbility.Slash, 1));
                Abilities.Add(new PlayerAbility(
                                  "rend", 25, 1, WarriorAbility.Rend, 1));
                Abilities.Add(new PlayerAbility(
                                  "block", 25, 1, WarriorAbility.Block, 1));
                Abilities.Add(new PlayerAbility(
                                  "berserk", 40, 1, WarriorAbility.Berserk, 1));
                Abilities.Add(new PlayerAbility(
                                  "disarm", 25, 1, WarriorAbility.Disarm, 1));
                break;

            case PlayerClassType.Archer:
                for (int i = 0; i < 3; i++)
                {
                    Inventory.Add(new HealthPotion(PotionStrength.Minor));
                }
                Abilities            = new List <PlayerAbility>();
                Strength             = 10;
                Dexterity            = 15;
                Intelligence         = 5;
                Constitution         = 10;
                MaxComboPoints       = Dexterity * 10;
                ComboPoints          = MaxComboPoints;
                CanWearCloth         = true;
                CanWearLeather       = true;
                CanUseBow            = true;
                CanUseDagger         = true;
                CanUseOneHandedSword = true;
                Inventory.Add(new Weapon(Level, WeaponType.Bow));
                Inventory.Add(new Armor(
                                  1, ArmorType.Leather, ArmorSlot.Head));
                Inventory.Add(new Armor(
                                  1, ArmorType.Leather, ArmorSlot.Chest));
                Inventory.Add(new Armor(
                                  1, ArmorType.Leather, ArmorSlot.Legs));
                Inventory.Add(new Quiver("basic quiver", 50, 15));
                Abilities.Add(new PlayerAbility("precise shot", 40, 1,
                                                ArcherAbility.Precise, 1));
                Abilities.Add(new PlayerAbility(
                                  "gut shot", 25, 1, ArcherAbility.Gut, 1));
                Abilities.Add(new PlayerAbility(
                                  "stun shot", 25, 1, ArcherAbility.Stun, 1));
                Abilities.Add(new PlayerAbility("double shot", 25, 1,
                                                ArcherAbility.Double, 1));
                Abilities.Add(new PlayerAbility("wound shot", 40, 1,
                                                ArcherAbility.Wound, 1));
                Abilities.Add(new PlayerAbility("distance shot", 25, 1,
                                                ArcherAbility.Distance, 1));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            MaxHitPoints   = Constitution * 10;
            HitPoints      = MaxHitPoints;
            MaxCarryWeight = (int)(Strength * 2.5);
            DodgeChance    = Dexterity * 1.5;
        }
コード例 #12
0
    public void configGamePlayer(PlayerClassType playerClassCongfig, int playerRefID, string playerName, SpawnObject spawn)
    {
        this.playerRefID = playerRefID;
        playerClass = playerClassCongfig.playerClass;

        if (this.playerClass == PlayerClassType.ClassList.GAME_MASTER)
        {
            GameSessionManager gameManager = this.gameObject.GetComponent<GameSessionManager>();
            gameManager.scriptEnabled = true;
        }
        else
        {
            SpaceshipController spaceshipController = this.GetComponent<SpaceshipController>();
            HealthSystem spaceshipHealth = this.GetComponent<HealthSystem>();
            StealSystem spaceshipSteal = this.GetComponent<StealSystem>();
            CombatSystem spaceshipCombat = this.GetComponent<CombatSystem>();
            AbilitySystem abilitySystem = this.GetComponent<AbilitySystem>();

            spaceshipController.PlayerName = playerName;
            spaceshipController.playerRefID = playerRefID;
            spaceshipController.scriptEnabled = true;
            spaceshipController.spriteName = playerClassCongfig.shipSprite.name;
            spaceshipController.transformScale = playerClassCongfig.transformScale;
            spaceshipController.colliderSize = playerClassCongfig.colliderSize;

            abilitySystem.config = playerClass;
            Debug.Log (spawn.location);
            spaceshipHealth.respawnLocation = spawn.location;
            spaceshipHealth.respawnRotation = spawn.rotation;

            spaceshipSteal.playerRefID = this.playerRefID;
            spaceshipSteal.playerName = playerName;

            if (spawnGamePrefabs) {
                if (planetPrefab != null && satellitePrefab != null && basePrefab != null)
                {
                    planetReference = (GameObject)Instantiate(planetPrefab,
                        transform.position + playerClassCongfig.planetOffset,
                        transform.rotation);
                    NetworkServer.Spawn(planetReference);

                    SatelliteController satelliteControl = satellitePrefab.GetComponent<SatelliteController>();
                    HealthSystem satelliteHealth = satellitePrefab.GetComponent<HealthSystem>();
                    satelliteControl.orbitCentre = planetReference.transform.position;
                    satelliteControl.playerRefID = this.playerRefID;
                    satelliteHealth.respawnLocation = planetReference.transform.position + new Vector3(0,-satelliteControl.orbitRadius,0);
                    satelliteReference = (GameObject)Instantiate(satellitePrefab,
                        planetReference.transform.position,
                        transform.rotation);
                    NetworkServer.Spawn(satelliteReference);

                    StealSystem baseSteal = basePrefab.GetComponent<StealSystem>();
                    baseSteal.playerRefID = this.playerRefID;
                    baseReference = (GameObject)Instantiate(basePrefab,
                        planetReference.transform.position + playerClassCongfig.baseOffset,
                        transform.rotation);
                    NetworkServer.Spawn(baseReference);
                }
            }
        }
    }
コード例 #13
0
 private void CmdSyncLobbyClass(PlayerClassType.ClassList classSync)
 {
     this.selectedClass = classSync;
 }
コード例 #14
0
 /// <summary>Gets the ship constraints that define the player class' ship information.</summary>
 /// <param name="playerClass">The player class.</param>
 /// <returns>The ship constraints.</returns>
 public static string GetShipFactoryName(this PlayerClassType playerClass)
 {
     return(ShipLookup[playerClass]);
 }
コード例 #15
0
        /// <summary>Load saves of version 0.</summary>
        private int Restore0(IManager manager, int playerNumber)
        {
            var undo = new Stack <Action>();

            try
            {
                // Read the player's class and create the ship.
                var playerClass = (PlayerClassType)_data.ReadByte();
                PlayerClass = playerClass;

                // Read the respawn position.
                var position = _data.ReadFarPosition();

                // Create the ship.
                var avatar = EntityFactory.CreatePlayerShip(manager, playerClass, playerNumber, position);
                undo.Push(() => manager.RemoveEntity(avatar));

                // Get the elements we need to save.
                var attributes =
                    (Attributes <AttributeType>)manager.GetComponent(avatar, Attributes <AttributeType> .TypeId);
                var experience = (Experience)manager.GetComponent(avatar, Experience.TypeId);
                var equipment  = (ItemSlot)manager.GetComponent(avatar, ItemSlot.TypeId);
                var inventory  = (Inventory)manager.GetComponent(avatar, Inventory.TypeId);

                // Clean out default equipment.
                if (equipment.Item > 0)
                {
                    // This will recursively delete all items in child slots.
                    manager.RemoveEntity(equipment.Item);
                }

                // Clear default inventory. Iterate backwards to be compatible with
                // both fixed and flexible length inventories.
                for (var i = inventory.Capacity - 1; i >= 0; --i)
                {
                    var item = inventory[i];
                    if (item > 0)
                    {
                        manager.RemoveEntity(item);
                    }
                }

                // Read back experience. Disable while setting to suppress message.
                experience.Enabled = false;
                experience.Value   = _data.ReadInt32();
                experience.Enabled = true;

                // Restore attributes. Use special packetizer implementation only
                // adjusting the actual attribute data, not the base data such as
                // entity id (which we want to keep).
                attributes.DepacketizeLocal(_data);

                // Disable recomputation while fixing equipped item ids.
                attributes.Enabled = false;

                // Restore equipment. This whole part is a bit messy. We first have to
                // read back all stored items, then link them back together the way they
                // were before. To do this without breaking the simulation in case
                // something goes wrong, we store those links in an extra dictionary and
                // set all references to zero until we have all items. This dictionary
                // maps the new item id to the old slot id the item was in. We get the
                // translation of the old component ids to the new ones from the
                // depacketizing operation and accumulate all changes in an extra map.
                var itemIdMapping = new Dictionary <int, int>();
                // This is used to get the change in component ids from reading the item
                // entities back after serialization.
                var componentIdMap = new Dictionary <int, int>();
                // See how many items we can expect.
                var equipmentCount = _data.ReadInt32();
                for (var i = 0; i < equipmentCount; ++i)
                {
                    // Read old ids and item entity.
                    var oldSlotId = _data.ReadInt32();
                    var newItemId = manager.DepacketizeEntity(_data, componentIdMap);
                    itemIdMapping.Add(newItemId, oldSlotId);

                    // Null out any slot references to avoid trying to remove non-existent
                    // stuff on undo (when something else fails).
                    foreach (ItemSlot slot in manager.GetComponents(newItemId, ItemSlot.TypeId))
                    {
                        slot.SetItemUnchecked(0);
                    }

                    // Push undo command.
                    undo.Push(() => manager.RemoveEntity(newItemId));
                }

                // No rebuild the equipment tree by restoring the links.
                foreach (var entry in itemIdMapping)
                {
                    // Get the new slot id by looking up the new component id based on the old one.
                    // There's one special case: the slot is not in our component map. This means
                    // the slot was not on one of the equipped items, and therefore has to be
                    // our equipment.
                    var newItemId = entry.Key;
                    var oldSlotId = entry.Value;
                    if (componentIdMap.ContainsKey(oldSlotId))
                    {
                        // Known component, so it has to be a slot on an item.
                        var newSlot = (ItemSlot)manager.GetComponentById(componentIdMap[oldSlotId]);

                        // Set the slot's content to the item's new id.
                        newSlot.SetItemUnchecked(newItemId);

                        // Undo linking for entity removal above (to avoid duplicate removals).
                        undo.Push(() => newSlot.SetItemUnchecked(0));
                    }
                    else
                    {
                        // Unknown, so it has to be our equipment.
                        System.Diagnostics.Debug.Assert(equipment.Item == 0, "Got multiple equipment tree roots.");
                        equipment.SetItemUnchecked(newItemId);

                        // Undo linking for entity removal above (to avoid duplicate removals).
                        undo.Push(() => equipment.SetItemUnchecked(0));
                    }
                }

                // Reenable attribute updating and trigger recomputation.
                attributes.Enabled = true;
                attributes.RecomputeAttributes();

                // Restore inventory, read back the stored items.
                var inventoryCount = _data.ReadInt32();
                if (_data.ReadBoolean())
                {
                    // Fixed size inventory.
                    inventory.Capacity = _data.ReadInt32();
                    for (var i = 0; i < inventoryCount; i++)
                    {
                        var slot = _data.ReadInt32();
                        var item = manager.DepacketizeEntity(_data);
                        inventory.Insert(slot, item);
                    }
                }
                else
                {
                    // List inventory.
                    for (var i = 0; i < inventoryCount; ++i)
                    {
                        var item = manager.DepacketizeEntity(_data);
                        inventory.Add(item);
                    }
                }

                return(avatar);
            }
            catch (Exception)
            {
                // Clean up what we created.
                while (undo.Count > 0)
                {
                    // Looks funny, don't it? ;)
                    undo.Pop()();
                }
                throw;
            }
        }
コード例 #16
0
        /// <summary>Take a snapshot of a character's current state in a running game.</summary>
        /// <param name="manager">The component system manager.</param>
        /// <param name="avatar">The avatar to take a snapshot of.</param>
        public void Capture(IManager manager, int avatar)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (avatar < 1)
            {
                throw new ArgumentException(@"Invalid avatar specified.", "avatar");
            }

            // Get the elements we need to save.
            var playerClass = (PlayerClass)manager.GetComponent(avatar, ComponentSystem.Components.PlayerClass.TypeId);
            var respawn     = (Respawn)manager.GetComponent(avatar, Respawn.TypeId);
            var experience  = (Experience)manager.GetComponent(avatar, Experience.TypeId);
            var attributes  = (Attributes <AttributeType>)manager.GetComponent(avatar, Attributes <AttributeType> .TypeId);
            var equipment   = (ItemSlot)manager.GetComponent(avatar, ItemSlot.TypeId);
            var inventory   = (Inventory)manager.GetComponent(avatar, Inventory.TypeId);

            // Check if we have everything we need.
            if (playerClass == null ||
                respawn == null ||
                attributes == null ||
                equipment == null ||
                inventory == null)
            {
                throw new ArgumentException(@"Invalid avatar specified.", "avatar");
            }

            // Make the actual snapshot via serialization.
            if (_data != null)
            {
                _data.Dispose();
            }
            _data = new Packet();

            // Write file version.
            _data.Write(Version);

            // Store the player class. Needed to create the actual ship when
            // loading. Also update the profile accordingly (should never
            // change, but who knows...)
            PlayerClass = playerClass.Value;
            _data.Write((byte)playerClass.Value);

            // Save the current spawning position.
            _data.Write(respawn.Position);

            // Store experience.
            _data.Write(experience.Value);

            // Store the attribute base values, just use serialization. This
            // is a slightly adjusted serialization method which does not touch
            // the base class (as we don't need that).
            attributes.PacketizeLocal(_data);

            // Store the equipment tree. We do this by writing all actually equipped
            // items and their current id, and the id of the item that is now their
            // parent. This allows connecting them back after deserializing them into
            // new entities with different ids.
            _data.Write(equipment.AllItems.Count());
            foreach (var slot in equipment.AllSlots.Where(s => s.Item > 0))
            {
                // Write old id of containing slot and id of stored item.
                _data.Write(slot.Id);
                manager.PacketizeEntity(_data, slot.Item);
            }

            // And finally, the inventory. Same as with the equipment, we have
            // to serialize the actual items in it. This is not as complicated
            // as the equipment, though, as it's not a tree, just a plain list.
            _data.Write(inventory.Count);
            _data.Write(inventory.IsReadOnly);
            if (inventory.IsReadOnly)
            {
                // Fixed length inventory, write capacity and index for each item.
                _data.Write(inventory.Capacity);
                for (var slot = 0; slot < inventory.Capacity; ++slot)
                {
                    var item = inventory[slot];
                    if (item > 0)
                    {
                        _data.Write(slot);
                        manager.PacketizeEntity(_data, item);
                    }
                }
            }
            else
            {
                // List inventory, just dump all the items.
                foreach (var item in inventory)
                {
                    manager.PacketizeEntity(_data, item);
                }
            }
        }
コード例 #17
0
        /// <summary>
        ///     Loads this profile from disk. If loading fails this will default to a new profile with the fall-back character
        ///     class.
        /// </summary>
        /// <exception cref="ArgumentException">Profile name is invalid.</exception>
        public void Load(string name)
        {
            if (InvalidCharPattern.IsMatch(name))
            {
                throw new ArgumentException(@"Invalid profile name, contains invalid character.", "name");
            }

            // Figure out the path, check if it's valid.
            Reset();
            Name = name;
            var profilePath = GetFullProfilePath();

            if (!File.Exists(profilePath))
            {
                throw new ArgumentException(@"Invalid profile name, no such file.", "name");
            }

            try
            {
                // Load the file contents, which are encrypted and compressed.
                var encrypted  = File.ReadAllBytes(profilePath);
                var compressed = Crypto.Decrypt(encrypted);
                var plain      = SimpleCompression.Decompress(compressed);

                // Now we have the plain data, handle it as a packet to read our
                // data from it.
                using (var packet = new Packet(plain, false))
                {
                    // Get file header.
                    if (!CheckHeader(packet.ReadByteArray()))
                    {
                        Logger.Error("Failed loading profile, invalid header, using default.");
                        return;
                    }

                    // Get the hash the data had when writing.
                    var hash = packet.ReadInt32();

                    // Get the player class.
                    var playerClass = (PlayerClassType)packet.ReadByte();

                    // And the actual data.
                    var data = packet.ReadPacketizable <Packet>();

                    // Check if the hash matches.
                    var hasher = new Hasher();
                    hasher.Write((byte)playerClass);
                    if (data != null)
                    {
                        hasher.Write(data);
                    }
                    if (hasher.Value == hash)
                    {
                        // All is well, keep the data, drop our old data, if any.
                        PlayerClass = playerClass;
                        _data       = data;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Failed loading profile, using default.", ex);
            }
        }
コード例 #18
0
ファイル: PlayerClass.cs プロジェクト: matrix4x4/Space
        /// <summary>Reset the component to its initial state, so that it may be reused without side effects.</summary>
        public override void Reset()
        {
            base.Reset();

            Value = PlayerClassType.Default;
        }
コード例 #19
0
        private static void DialogSpawns_Response(object sender, DialogResponseEventArgs e, PlayerClassType classId)
        {
            if (e.DialogButton != DialogButton.Left)
            {
                return;
            }

            if (!(e.Player is Player player))
            {
                return;
            }

            var spawns = new ClassSpawnRepository(ConnectionFactory.GetConnection).GetAllByClassType((int)classId);

            switch (classId)
            {
            default:
                player.Position = new Vector3(spawns.ElementAt(e.ListItem).PositionX, spawns.ElementAt(e.ListItem).PositionY, spawns.ElementAt(e.ListItem).PositionZ);
                break;
            }
        }