コード例 #1
0
 partial void DeleteInventoryItem(InventoryItem instance);
コード例 #2
0
 partial void UpdateInventoryItem(InventoryItem instance);
コード例 #3
0
 partial void InsertInventoryItem(InventoryItem instance);
コード例 #4
0
		private void detach_InventoryItems(InventoryItem entity)
		{
			this.SendPropertyChanging();
			entity.InventoryItemStatus = null;
		}
コード例 #5
0
		private void detach_InventoryItems(InventoryItem entity)
		{
			this.SendPropertyChanging();
			entity.PlayerCharacter = null;
		}
コード例 #6
0
ファイル: Player.cs プロジェクト: rdwoodring/mudadventure
        //public override void ReceiveAttack(int potentialdamage, string attackerName)
        //{
        //    //base(potentialdamage, attackerName);
        //}
        private void Save()
        {
            if (this.connected)
            {
                //saving player
                var playerQuery =
                    (from playercharacter in db.PlayerCharacters
                     where playercharacter.PlayerName.ToString().ToLower() == this.name.ToLower()
                     select playercharacter).First();

                playerQuery.X = this.x;
                playerQuery.Y = this.y;
                playerQuery.Z = this.z;

                playerQuery.TotalExperience = this.totalExperience;
                playerQuery.ExpThisLevel = this.currentLevelExp;

                playerQuery.Level = this.level;

                //now to save items in db

                //first let's get a list of all items currently saved for this player in the db
                //we're going to save the new items to the db, then delete all of these items, instead of trying to figure out
                //what the exact changes are.
                var dbItems = from item in db.InventoryItems
                              where item.PlayerName.ToLower() == this.name.ToLower()
                              select item;

                //let's start saving items to the db
                List<Item> items = this.inventory.ListInventory();
                foreach (Item item in items)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = item.Name;
                    invItem.ItemDescription = item.Description;
                    invItem.ItemWeight = item.Weight;
                    invItem.ItemRefNames = String.Join(",", item.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 10;
                    invItem.ItemType = item.GetType().ToString();

                    switch (item.GetType().ToString())
                    {
                        case "MUDAdventure.Items.Dagger":
                            invItem.ItemDamage = item.ToDagger().Damage;
                            invItem.ItemSpeed = item.ToDagger().Speed;
                            break;
                        case "MUDAdventure.Items.Sword":
                            invItem.ItemDamage = item.ToSword().Damage;
                            invItem.ItemSpeed = item.ToSword().Speed;
                            break;
                        case "MUDAdventure.Items.Axe":
                            invItem.ItemDamage = item.ToAxe().Damage;
                            invItem.ItemSpeed = item.ToAxe().Speed;
                            break;
                        case "MUDAdventure.Items.Light":
                            invItem.ItemCurrentFuel = item.ToLight().CurrentFuel;
                            invItem.ItemTotalFuel = item.ToLight().TotalFuel;
                            break;
                        case "MUDAdventure.Items.Headwear":
                            invItem.ItemDamage = item.ToHeadwear().ArmorValue;
                            break;
                        case "MUDAdventure.Items.Shirt":
                            invItem.ItemDamage = item.ToShirt().ArmorValue;
                            break;
                        case "MUDAdventure.Items.Gloves":
                            invItem.ItemDamage = item.ToGloves().ArmorValue;
                            break;
                        case "MUDAdventure.Items.Pants":
                            invItem.ItemDamage = item.ToPants().ArmorValue;
                            break;
                        case "MUDAdventure.Items.Boots":
                            invItem.ItemDamage = item.ToBoots().ArmorValue;
                            break;
                    }

                    playerQuery.InventoryItems.Add(invItem);
                }

                //TODO: save items that are wielded/worn/held etc.
                if (this.inventory.Wielded != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Wielded.Name;
                    invItem.ItemDescription = this.inventory.Wielded.Description;
                    invItem.ItemWeight = this.inventory.Wielded.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Wielded.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 1;
                    invItem.ItemType = this.inventory.Wielded.GetType().ToString();

                    switch (this.inventory.Wielded.GetType().ToString())
                    {
                        case "MUDAdventure.Items.Dagger":
                            invItem.ItemDamage = this.inventory.Wielded.ToDagger().Damage;
                            invItem.ItemSpeed = this.inventory.Wielded.ToDagger().Speed;
                            break;
                        case "MUDAdventure.Items.Sword":
                            invItem.ItemDamage = this.inventory.Wielded.ToSword().Damage;
                            invItem.ItemSpeed = this.inventory.Wielded.ToSword().Speed;
                            break;
                        case "MUDAdventure.Items.Axe":
                            invItem.ItemDamage = this.inventory.Wielded.ToAxe().Damage;
                            invItem.ItemSpeed = this.inventory.Wielded.ToAxe().Speed;
                            break;
                        //case: MUDAdventure.Sword, spear, etc, etc
                    }

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Light != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Light.Name;
                    invItem.ItemDescription = this.inventory.Light.Description;
                    invItem.ItemWeight = this.inventory.Light.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Light.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 2;
                    invItem.ItemType = this.inventory.Light.GetType().ToString();

                    invItem.ItemCurrentFuel = this.inventory.Light.ToLight().CurrentFuel;
                    invItem.ItemTotalFuel = this.inventory.Light.ToLight().TotalFuel;

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Head != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Head.Name;
                    invItem.ItemDescription = this.inventory.Head.Description;
                    invItem.ItemWeight = this.inventory.Head.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Head.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 3;
                    invItem.ItemType = this.inventory.Head.GetType().ToString();

                    invItem.ItemArmorValue = this.inventory.Head.ArmorValue;

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Shirt != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Shirt.Name;
                    invItem.ItemDescription = this.inventory.Shirt.Description;
                    invItem.ItemWeight = this.inventory.Shirt.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Shirt.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 4;
                    invItem.ItemType = this.inventory.Shirt.GetType().ToString();

                    invItem.ItemArmorValue = this.inventory.Shirt.ArmorValue;

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Gloves != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Gloves.Name;
                    invItem.ItemDescription = this.inventory.Gloves.Description;
                    invItem.ItemWeight = this.inventory.Gloves.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Gloves.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 6;
                    invItem.ItemType = this.inventory.Gloves.GetType().ToString();

                    invItem.ItemArmorValue = this.inventory.Gloves.ArmorValue;

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Pants != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Pants.Name;
                    invItem.ItemDescription = this.inventory.Pants.Description;
                    invItem.ItemWeight = this.inventory.Pants.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Pants.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 7;
                    invItem.ItemType = this.inventory.Pants.GetType().ToString();

                    invItem.ItemArmorValue = this.inventory.Pants.ArmorValue;

                    playerQuery.InventoryItems.Add(invItem);
                }

                if (this.inventory.Boots != null)
                {
                    InventoryItem invItem = new InventoryItem();
                    invItem.PlayerName = this.name;
                    invItem.ItemName = this.inventory.Boots.Name;
                    invItem.ItemDescription = this.inventory.Boots.Description;
                    invItem.ItemWeight = this.inventory.Boots.Weight;
                    invItem.ItemRefNames = String.Join(",", this.inventory.Boots.RefNames.ToArray());
                    invItem.ItemInventoryStatusCode = 9;
                    invItem.ItemType = this.inventory.Boots.GetType().ToString();

                    invItem.ItemArmorValue = this.inventory.Boots.ArmorValue;

                    playerQuery.InventoryItems.Add(invItem);
                }

                //now that the new items are saved, let's delete all the old items.
                foreach (var item in dbItems)
                {
                    db.InventoryItems.DeleteOnSubmit(item);
                }

                //playerQuery.level = this.level;
                //playerQuery.ExpUntilNext = this.expUntilNext;
                this.writeToClient("Saving " + this.name + "...\r\n");

                try
                {
                    db.SubmitChanges();
                    //this.writeToClient(this.name + " saved.");
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                    Debug.Print(ex.StackTrace);
                }
            }
        }