/** * After generating a list of Items in the StartStore method Deliver method will put every * Item up for sale one by one so that the Consumer knows what's for sale. DeliverItem method * will also write a log for every Item recived to a file. */ public void DeliverItem(Iitem item) { lock (_lock) { _items.Add(item); _log.Write(Name, "Recieved item: " + item.GetName() + " - " + item.GetDesc() + ". Sells for: " + item.GetPrice() + "Yen"); // Output that the store got a new item. lock (Console.Out) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0}\n - Got the new item: " + "{1}\n - " + "{2}\n | Selling for: " + "{3} ¥\n", Name, item.GetName(), item.GetDesc(), item.GetPrice()); Console.ForegroundColor = ConsoleColor.White; } } }
public string LookIn() { if ((IsOpenable && Opened) || !IsOpenable) { StringBuilder sb = new StringBuilder(); sb.AppendLine(Name + " contents:"); if (GetContents().Count > 0) { foreach (string itemID in GetContents()) { Iitem tempItem = Items.GetByID(itemID); sb.AppendLine(tempItem.Name); } sb.AppendLine(); } else { sb.AppendLine("\n[ EMPTY ]\n"); } OnLookedIn(new ItemEventArgs(ItemEvent.LOOK_IN, this.Id)); return(sb.ToString()); } else { return("You must open " + Name + " before seeing what is in it."); } }
public bool StoreItem(string id) { bool added = false; Iitem temp = Items.GetByID(id); //containers can't be encumbered they can only hold so much if ((IsOpenable && Opened) || !IsOpenable) { if (CurrentWeight + temp.Weight <= WeightLimit) { CurrentWeight += temp.Weight; Contents.Add(temp.Id.ToString()); added = true; if (Worn) { Weight = CurrentWeight - (CurrentWeight * ReduceCarryWeightBy); } Save(); OnStored(new ItemEventArgs(ItemEvent.STORE, this.Id)); } } return(added); }
/** * Creates an item with fixed features */ public static Iitem CreateSpecific(double price, params ItemProperties[] parameters) { Iitem newItem = Create(price); foreach (ItemProperties prop in parameters) { switch (prop) { case ItemProperties.Gold: newItem = new FeatureDecoratorGold(newItem); break; case ItemProperties.Diamond: newItem = new FeatureDecoratorDiamond(newItem); break; case ItemProperties.Furry: newItem = new FeatureDecoratorFurry(newItem); break; case ItemProperties.Leather: newItem = new FeatureDecoratorLeather(newItem); break; case ItemProperties.TigerPrint: newItem = new FeatureDecoratorTigerPrint(newItem); break; default: throw new ArgumentException("Did not know how to handle ItemProporty : " + prop); } } return(newItem); }
/** * This method will let the consumer buy the item one at the time and then * return the item. The method will also write to a logg of the process off buying an item. */ public Iitem Buy(Iitem item) { lock (_lock){ // Lock so we don't have two threads trying to buy the same thing // is the item still for sale? if (_items.Contains(item)) // yes { int index = _items.IndexOf(item); Iitem itemToReturn = _items[index]; _items.Remove(item); _log.Write(Name, "Sold item: " + itemToReturn.GetName() + " - " + itemToReturn.GetDesc() + ". For: " + itemToReturn.GetPrice()); return(itemToReturn); } else // no { _log.Write(Name, "Item allready sold: " + item.GetName() + " - " + item.GetDesc()); return(null); } } }
static void Main(string[] args) { Sword sword = new Sword("Sword of Destiny"); sword.Equip(); sword.TakeDamage(20); sword.Sell(); sword.TurnIn(); Axe axe = new Axe("Fury Axe"); axe.Equip(); axe.TakeDamage(10); axe.Sell(); // Create inventory Iitem[] inventory = new Iitem[2]; inventory[0] = sword; inventory[1] = axe; for (int i = 0; i < inventory.Length; i++) { IpartOfQuest questItem = inventory[i] as IpartOfQuest; if (questItem != null) { questItem.TurnIn(); } } }
private void RpcShoow(Iitem item, int faceHorizontal, float angle, float powerValue, ItemEnum.ItemType arms) { if (item.transform.parent) { ItemMgr.instance.CreateItem(arms); } item.Shoot(transform, faceHorizontal, angle, powerValue); }
public void CreateSpesificTest() { Iitem checkItem = ItemFactory.CreateSpecific(100, _itemProperties); foreach (var property in _descriptions) { Assert.True(Regex.Matches(checkItem.GetDesc(), property).Count == 1); } }
public static Iitem GetByIDFromList(List <string> id) { if (id.Count > 0) { Iitem result = GetByID(id[0]); return(result); } return(null); }
/// <summary> /// Subscribes the trigger to an item event based on the ItemTrigger.TriggerOn property /// </summary> /// <param name="result"></param> /// <param name="trigger"></param> private static void SubscribeToCorrectEvent(Iitem result, ItemTrigger trigger) { if (!string.IsNullOrEmpty(trigger.TriggerOn)) { switch (trigger.TriggerOn.ToUpper()) { case "OPEN": result.ContainerOpened += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "CLOSE": result.ContainerClosed += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "DETERIORATE": result.Deteriorated += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "IMPROVE": result.Improved += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "WORN": result.ItemWorn += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "IGNITE": result.Ignited += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "EXTINGUISH": result.Extinguished += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "DRAIN": result.Drained += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "RECHARGE": result.Recharged += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "EXAMINE": result.Examined += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "LOOKIN": result.LookedIn += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "STORE": result.Stored += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "RETRIEVE": result.Retrieved += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "CONSUME": result.Consumed += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; case "WIELD": result.Wielded += new EventHandler<ItemEventArgs>(trigger.HandleEvent); break; default: break; } } }
public void CreateRandomGotNoDuplicatePropertysTest() { for (int i = 0; i < 1000; i++) { Iitem checkItem = ItemFactory.CreateRandom(100); foreach (var property in _descriptions) { Assert.True(Regex.Matches(checkItem.GetDesc(), property).Count < 2); } } }
public static Iitem GetByID(string id) { MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("World"); MongoCollection collection = db.GetCollection("Items"); var doc = collection.FindOneAs <BsonDocument>(Query.EQ("_id", ObjectId.Parse(id))); Iitem result = null; if (doc != null) { result = ItemFactory.CreateItem(doc["_id"].AsObjectId); } return(result); }
public static void DeChargeLightSources() { MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase db = MongoUtils.MongoData.GetDatabase("World"); MongoCollection collection = db.GetCollection("Items"); var doc = collection.FindAs <BsonDocument>(Query.And(Query.EQ("ItemType", 5), Query.EQ("isLit", true))); foreach (BsonDocument item in doc) { Iitem lightSource = GetByID(item["_id"].AsObjectId.ToString()); Iiluminate light = lightSource as Iiluminate; light.Drain(); } }
/// <summary> /// Adds the Items specified in the Inspector-editable arrays and adds them to the inventory object on its gameobject /// </summary> public void AddItems() { Inventory chest = gameObject.GetComponent <Inventory>(); if (chest != null) { foreach (Items itm in ItemObjects) { Iitem objItem = (Iitem)ItemDictionary.itemDict.GetItem(itm.itemName); if (objItem != null) { if (!itm.description.Equals("")) { objItem.Description = itm.description; } if (objItem is IWeapon) { IWeapon objWeap = (IWeapon)objItem; if (itm.damage > 0) { objWeap.damage = itm.damage; } if (itm.swingSpeed > 0) { objWeap.swingSpeed = itm.swingSpeed; } if (itm.range > 0) { objWeap.range = itm.range; } if (!itm.name.Equals("")) { objWeap.Name = itm.name; } chest.AddObject(objWeap, itm.itemAmount); } else { chest.AddObject(objItem, itm.itemAmount); } if (chest is GenericShop) //If the chest is a shop instance { ((GenericShop)chest).itemCost.Add(objItem, itm.cost); } } } chest.SaveInventory(); } }
static void Main(string[] args) { //create an instance of the sword class Sword sword = new Sword("Sword of Destiny"); //equip the sword sword.Equip(); //sell the sword sword.Sell(); //durability takes damage of 20 sword.Damage(20); Console.WriteLine(); //create an instance of the axe class Axe axe = new Axe("Axe of Wonders"); //equip the axe axe.Equip(); //sell the axe axe.Sell(); //durability takes damage of 10 axe.Damage(10); Console.WriteLine(); //create an Inventory so that you turn in items //this is an "array" of items Iitem[] inventory = new Iitem[2]; inventory[0] = sword; inventory[1] = axe; //loop through and turn in all quest items //create an index and set it to 0 which is less than the number of items in the inventory and increment the index for (int index = 0; index < inventory.Length; index++) { //check items to turn in from the inventory IPartOfQuest Items = inventory[index] as IPartOfQuest; //make sure the inventory is not empty and has an item in it. if (Items != null) { Items.TurnIn(); } } //await user input Console.ReadKey(); }
public static Iitem GetBestItem(List <Iitem> set) { Iitem bestItem = null; if (set.Count() > 0) { bestItem = set[0]; foreach (Iitem comparee in set) { if (bestItem == comparee) { continue; } bestItem = CompareItems(bestItem, comparee); } } return(bestItem); }
//we are going to base the best item on an accumulation of points based on every stat difference for the item private static Iitem CompareItems(Iitem bestItem, Iitem comparee) { List <int> scores = new List <int>(); List <Iitem> bothItems = new List <Iitem> { bestItem, comparee }; int index = 0; foreach (Iitem item in bothItems) { Iclothing clothing = item as Iclothing; Iweapon weapon = item as Iweapon; Icontainer container = item as Icontainer; if (clothing != null) { scores[index] += (int)clothing.CurrentDefense; } if (weapon != null) { scores[index] += (int)(weapon.CurrentMaxDamage - weapon.CurrentMinDamage); scores[index] += (int)weapon.AttackSpeed; //TODO: will need to figure out wear effects and player/target attack effects } if (container != null) { scores[index] += (int)container.WeightLimit / 100; scores[index] += (int)container.ReduceCarryWeightBy * 100; } index++; } if (scores[1] > scores[0]) { bestItem = bothItems[1]; } return(bestItem); }
void setInteriorList() { Interior.transform.FindChild("build_content").transform.FindChild("name").GetComponent <Text>().text = ""; Interior.transform.FindChild("build_content").transform.FindChild("content").GetComponent <Text>().text = ""; Coin.SetActive(false); Coin.transform.FindChild("Text").GetComponent <Text>().text = ""; Star.SetActive(false); Star.transform.FindChild("Text").GetComponent <Text>().text = ""; for (int i = 0; i < Interiorlist.transform.childCount; i++) { Destroy(Interiorlist.transform.GetChild(i).gameObject); } for (int i = 0; i < GameData.InteriorList.Count; i++) { GameObject Iitem; Iitem = Instantiate(InItem, InItem.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; Iitem.name = "" + i; Iitem.transform.SetParent(Interiorlist.transform); Iitem.transform.localScale = new Vector3(1, 1, 1); Iitem.GetComponent <InteriorItem>().type = InteriotType; if (InteriotType == 0) { Iitem.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Shop/Stand")[i]; } else if (InteriotType == 1) { Iitem.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Shop/Wall")[i]; } else if (InteriotType == 2) { Iitem.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Shop/Door")[i]; } else if (InteriotType == 3) { Iitem.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Shop/Counter")[i]; } } }
/// <summary> /// Loops through the triggers array in the BsonDocument and adds them to the Item /// </summary> /// <param name="result"></param> /// <param name="tempItem"></param> /// <returns></returns> private static Iitem AddTriggersToItem(Iitem result, BsonDocument tempItem) { //This method could probably just return an ITriggers List instead result.ItemTriggers = new List<ITrigger>(); // result.SpeechTriggers = new List<ITrigger>(); if (tempItem["Triggers"].AsBsonArray.Count > 0) { //loop through the triggers, an item can have multiple triggers for different things foreach (BsonDocument doc in tempItem["Triggers"].AsBsonArray) { ItemTrigger trigger = new ItemTrigger(doc); SubscribeToCorrectEvent(result, trigger); //for most scripts we are going to want the playerID to then get anything else we may want within it like rooms, items, etc trigger.script.AddVariable(result.Owner, "ownerID"); result.ItemTriggers.Add(trigger); } } return result; }
public Iitem RetrieveItem(string id) { if ((IsOpenable && Opened) || !IsOpenable) { if (Contents.Contains(id)) { Iitem temp = Items.GetByID(id); CurrentWeight -= temp.Weight; Contents.Remove(id); Save(); if (Worn) { Weight = CurrentWeight - (CurrentWeight * ReduceCarryWeightBy); } OnRetrieved(new ItemEventArgs(ItemEvent.RETRIEVE, this.Id)); return(temp); } } return(null); }
/** * This method will start the Store and generete random items and * put a pricetag on it. */ public void StartStore() { while (_running || _items.Count > 0) { if (_running) { double price = _rng.Next(10, 5500); Iitem newItem = ItemFactory.CreateRandom(price); _log.Write(Name, "Made item: " + newItem.GetName() + " - " + newItem.GetDesc() + ". Sells For: " + newItem.GetPrice()); DeliverItem(newItem); } Thread.Sleep(1000); } }
/// <summary> /// Loops through the triggers array in the BsonDocument and adds them to the Item /// </summary> /// <param name="result"></param> /// <param name="tempItem"></param> /// <returns></returns> private static Iitem AddTriggersToItem(Iitem result, BsonDocument tempItem) { //This method could probably just return an ITriggers List instead result.ItemTriggers = new List <ITrigger>(); // result.SpeechTriggers = new List<ITrigger>(); if (tempItem["Triggers"].AsBsonArray.Count > 0) { //loop through the triggers, an item can have multiple triggers for different things foreach (BsonDocument doc in tempItem["Triggers"].AsBsonArray) { ItemTrigger trigger = new ItemTrigger(doc); SubscribeToCorrectEvent(result, trigger); //for most scripts we are going to want the playerID to then get anything else we may want within it like rooms, items, etc trigger.script.AddVariable(result.Owner, "ownerID"); result.ItemTriggers.Add(trigger); } } return(result); }
public static Iitem CreateItem(ObjectId id) { BsonDocument tempItem = null; if (id != null) //id got passed in so we are looking for a specific edible item { MongoCollection itemCollection = MongoUtils.MongoData.GetCollection("World", "Items"); tempItem = itemCollection.FindOneAs <BsonDocument>(Query.EQ("_id", id)); } Iitem result = null; try { result = BsonSerializer.Deserialize <Items>(tempItem); //add any triggers to the item result = AddTriggersToItem(result, tempItem); //may be easier to just do result.ItemTriggers = AddTriggersToItem(tempItem); } catch (Exception ex) { result.ToString(); } return(result); }
public FeatureDecoratorGold(Iitem orginalItem) { _original_item = orginalItem; }
//we are going to base the best item on an accumulation of points based on every stat difference for the item private static Iitem CompareItems(Iitem bestItem, Iitem comparee) { List<int> scores = new List<int>(); List<Iitem> bothItems = new List<Iitem> { bestItem, comparee }; int index = 0; foreach (Iitem item in bothItems) { Iclothing clothing = item as Iclothing; Iweapon weapon = item as Iweapon; Icontainer container = item as Icontainer; if (clothing != null) { scores[index] += (int)clothing.CurrentDefense; } if (weapon != null) { scores[index] += (int)(weapon.CurrentMaxDamage - weapon.CurrentMinDamage); scores[index] += (int)weapon.AttackSpeed; //TODO: will need to figure out wear effects and player/target attack effects } if (container != null) { scores[index] += (int)container.WeightLimit / 100; scores[index] += (int)container.ReduceCarryWeightBy * 100; } index++; } if (scores[1] > scores[0]) { bestItem = bothItems[1]; } return bestItem; }
void RemoveItem(Iitem item) { Items.Remove(item); }
//public static DropItem GetItem2() // //{ // if (Instance.dropItem.Count > 0) // // { // var obj = Instance.dropItem.Dequeue(); // obj.transform.SetParent(null); // obj.gameObject.SetActive(true); // return obj; // } // else // // { // var newObj1 = Instance.CreateNewItem2(); //새로 생성 후 빌려준다. // newObj1.gameObject.SetActive(true); // newObj1.transform.SetParent(null); // return newObj1; // } //} public static void ReturnObject(Iitem obj) //몬스터를 요청한 자가 사용후 반환할 때 { obj.gameObject.SetActive(false); obj.transform.SetParent(Instance.transform); Instance.myItem.Enqueue(obj); }
void AddItem(Iitem item) { Items.Add(item); }
public void CreateTest() { Iitem item = ItemFactory.Create(99.99); Assert.True(item != null && item.GetPrice() == 99.99); }
public void init() { _store = new Store("test"); _testItem = new Item("Audi", 100, "Dette er en bil"); }
public ItemController(Iitem repo) { _repo = repo; }
public FeatureDecoratorLeather(Iitem originalItem) { _original_item = originalItem; }
/// <summary> /// Subscribes the trigger to an item event based on the ItemTrigger.TriggerOn property /// </summary> /// <param name="result"></param> /// <param name="trigger"></param> private static void SubscribeToCorrectEvent(Iitem result, ItemTrigger trigger) { if (!string.IsNullOrEmpty(trigger.TriggerOn)) { switch (trigger.TriggerOn.ToUpper()) { case "OPEN": result.ContainerOpened += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "CLOSE": result.ContainerClosed += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "DETERIORATE": result.Deteriorated += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "IMPROVE": result.Improved += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "WORN": result.ItemWorn += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "IGNITE": result.Ignited += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "EXTINGUISH": result.Extinguished += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "DRAIN": result.Drained += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "RECHARGE": result.Recharged += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "EXAMINE": result.Examined += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "LOOKIN": result.LookedIn += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "STORE": result.Stored += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "RETRIEVE": result.Retrieved += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "CONSUME": result.Consumed += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; case "WIELD": result.Wielded += new EventHandler <ItemEventArgs>(trigger.HandleEvent); break; default: break; } } }