/// <summary> /// Add a new entry to the data store. /// </summary> public void AddStoreEntry(StoreEntry newEntry) { // check if the entry already exists if (_proxyStore.Any(_ => _.key.EqualsIgnoreCase(newEntry.key))) { throw new InvalidOperationException("Entry already exists"); } // update proxy store _proxyStore.Add(newEntry); NotifyPropertyChanged("StoreEntry"); }
//the basic initialization of the item store protected virtual ItemStore GenerateItemStore() { //load the item entry structure. Note that contents is specific because EntryStructure can be //overloaded in child entities ItemStore newstore = new ItemStore(StoreEntry.CloneList(EntryStructure)); //write the new display column number to the store newstore.DisplayColumns = DisplayColumns; newstore.RegisterEntries(); return(newstore); }
public void AddPile(string name, int price) { if (HasPile(name)) { return; } StoreEntry e = new StoreEntry(); e.name = name; e.elements = new List <Buyable>(); e.price = price; e.basePrice = price; piles.Add(e); }
private bool TryGet(string key, out StoreEntry counter) { if (_counters.TryGetValue(key, out counter)) { if (counter.Ttl >= _clock.UtcNow) { return(true); } _counters.Remove(key); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="T:SqlAclManager" /> class. /// </summary> /// <param name="storeEntry">The <see cref="StoreEntry" /> delegate.</param> /// <param name="deleteEntries">The <see cref="DeleteEntries" /> delegate.</param> /// <param name="renameResource">The <see cref="RenameResource" /> delegate.</param> /// <param name="retrieveAllEntries">The <see cref="RetrieveAllEntries" /> delegate.</param> /// <param name="retrieveEntriesForResource">The <see cref="RetrieveEntriesForResource" /> delegate.</param> /// <param name="retrieveEntriesForSubject">The <see cref="RetrieveEntriesForSubject" /> delegate.</param> public SqlAclManager( StoreEntry storeEntry, DeleteEntries deleteEntries, RenameResource renameResource, RetrieveAllEntries retrieveAllEntries, RetrieveEntriesForResource retrieveEntriesForResource, RetrieveEntriesForSubject retrieveEntriesForSubject) { _storeEntry = storeEntry ?? throw new ArgumentNullException(nameof(storeEntry)); _deleteEntries = deleteEntries ?? throw new ArgumentNullException(nameof(deleteEntries)); _renameResource = renameResource ?? throw new ArgumentNullException(nameof(renameResource)); _retrieveAllEntries = retrieveAllEntries ?? throw new ArgumentNullException(nameof(retrieveAllEntries)); _retrieveEntriesForResource = retrieveEntriesForResource ?? throw new ArgumentNullException(nameof(retrieveEntriesForResource)); _retrieveEntriesForSubject = retrieveEntriesForSubject ?? throw new ArgumentNullException(nameof(retrieveEntriesForSubject)); }
public StoreEntry FindConsumableEntry(Type[] types, int amount) { //find a match in this key's store int index = StoreEntry.IndexOfType(_Store.StoreEntries, types, true); //check if there was a match, and there is a sufficient amount if (index > -1 && _Store.StoreEntries[index].Amount >= amount) { //return a reference to this return(_Store.StoreEntries[index]); } //nothing suitable found, return null return(null); }
static StoreEntry getData(string key) { StoreEntry ret = null; foreach (XmlNode node in dataStore.DocumentElement.ChildNodes) { if (node.Attributes["key"].Value == key) { ret = new StoreEntry(); ret.key = key; ret.version = int.Parse(node.Attributes["version"].Value); ret.value = node.Attributes["value"].Value; } } return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="T:OracleAclManager" /> class. /// </summary> /// <param name="storeEntry">The <see cref="StoreEntry"/> delegate.</param> /// <param name="deleteEntries">The <see cref="DeleteEntries"/> delegate.</param> /// <param name="renameResource">The <see cref="RenameResource"/> delegate.</param> /// <param name="retrieveAllEntries">The <see cref="RetrieveAllEntries"/> delegate.</param> /// <param name="retrieveEntriesForResource">The <see cref="RetrieveEntriesForResource"/> delegate.</param> /// <param name="retrieveEntriesForSubject">The <see cref="RetrieveEntriesForSubject"/> delegate.</param> public OracleAclManager(StoreEntry storeEntry, DeleteEntries deleteEntries, RenameResource renameResource, RetrieveAllEntries retrieveAllEntries, RetrieveEntriesForResource retrieveEntriesForResource, RetrieveEntriesForSubject retrieveEntriesForSubject) { if(storeEntry == null) throw new ArgumentNullException("storeEntry"); if(deleteEntries == null) throw new ArgumentNullException("deleteEntries"); if(renameResource == null) throw new ArgumentNullException("renameResource"); if(retrieveAllEntries == null) throw new ArgumentNullException("retrieveAllEntries"); if(retrieveEntriesForResource == null) throw new ArgumentNullException("retrieveEntriesForResource"); if(retrieveEntriesForSubject == null) throw new ArgumentNullException("retrieveEntriesForSubject"); _storeEntry = storeEntry; _deleteEntries = deleteEntries; _renameResource = renameResource; _retrieveAllEntries = retrieveAllEntries; _retrieveEntriesForResource = retrieveEntriesForResource; _retrieveEntriesForSubject = retrieveEntriesForSubject; }
/// <summary> /// Update the data store with a new entry. /// </summary> public void UpdateStoreEntry(StoreEntry newEntry) { // the server MUST find a corresponding Store Entry // on [Server State].ProxyStore for the corresponding key var targetEntry = _proxyStore.FirstOrDefault(_ => _.key.EqualsIgnoreCase(newEntry.key)); if (targetEntry == null) { throw new InvalidOperationException("Cannot find Entry " + newEntry.key); } // skip version checking targetEntry.version++; // the server MUST set the value of [Store Entry].value targetEntry.value = newEntry.value; NotifyPropertyChanged("StoreEntry"); }
static List <StoreEntry> getExternalEntries() { List <StoreEntry> list = new List <StoreEntry>(); foreach (XmlNode node in dataStore.DocumentElement.ChildNodes) { StoreEntry ret = new StoreEntry(); ret.key = node.Attributes["key"].Value;; ret.version = int.Parse(node.Attributes["version"].Value); if (ret.version == -1) { continue; } ret.value = node.Attributes["value"].Value; list.Add(ret); } return(list); }
/// <summary> /// Initializes a new instance of the <see cref="T:SqlAclManager" /> class. /// </summary> /// <param name="storeEntry">The <see cref="StoreEntry"/> delegate.</param> /// <param name="deleteEntries">The <see cref="DeleteEntries"/> delegate.</param> /// <param name="renameResource">The <see cref="RenameResource"/> delegate.</param> /// <param name="retrieveAllEntries">The <see cref="RetrieveAllEntries"/> delegate.</param> /// <param name="retrieveEntriesForResource">The <see cref="RetrieveEntriesForResource"/> delegate.</param> /// <param name="retrieveEntriesForSubject">The <see cref="RetrieveEntriesForSubject"/> delegate.</param> public SqlAclManager(StoreEntry storeEntry, DeleteEntries deleteEntries, RenameResource renameResource, RetrieveAllEntries retrieveAllEntries, RetrieveEntriesForResource retrieveEntriesForResource, RetrieveEntriesForSubject retrieveEntriesForSubject) { if (storeEntry == null) { throw new ArgumentNullException("storeEntry"); } if (deleteEntries == null) { throw new ArgumentNullException("deleteEntries"); } if (renameResource == null) { throw new ArgumentNullException("renameResource"); } if (retrieveAllEntries == null) { throw new ArgumentNullException("retrieveAllEntries"); } if (retrieveEntriesForResource == null) { throw new ArgumentNullException("retrieveEntriesForResource"); } if (retrieveEntriesForSubject == null) { throw new ArgumentNullException("retrieveEntriesForSubject"); } _storeEntry = storeEntry; _deleteEntries = deleteEntries; _renameResource = renameResource; _retrieveAllEntries = retrieveAllEntries; _retrieveEntriesForResource = retrieveEntriesForResource; _retrieveEntriesForSubject = retrieveEntriesForSubject; }
public FormFlowInstance CreateInstance( string key, FormFlowInstanceId instanceId, Type stateType, object state, IReadOnlyDictionary <object, object> properties) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (stateType == null) { throw new ArgumentNullException(nameof(stateType)); } if (state == null) { throw new ArgumentNullException(nameof(state)); } properties ??= new Dictionary <object, object>(); var entry = new StoreEntry() { Key = key, StateTypeAssemblyQualifiedName = stateType.AssemblyQualifiedName, State = state, Properties = properties, Completed = false }; var serialized = _stateSerializer.Serialize(entry); var storeKey = GetKeyForInstance(instanceId); _store.SetState(storeKey, serialized); return(FormFlowInstance.Create(this, key, instanceId, stateType, state, properties)); }
//scans thru the contents for requested consumables and returns a list of all usable candidates. The foundentries boolean //array holds recod of previously found resources from other IItemStoreObjects previously scanned, and thus are ignored public List <StoreEntry> FindConsumableEntries(Type[] types, int[] amounts, ref bool[] foundentries) { List <StoreEntry> stores = new List <StoreEntry>(); for (int i = 0; i < types.Length; i++) { //ignore it if this has already been found in another storage if (foundentries[i]) { continue; } //find a match in this key's store foreach (ItemStore store in _Stores) { int index = StoreEntry.IndexOfType(store.StoreEntries, types[i], true); //check if there was a match, and there is a sufficient amount if (index > -1 && store.StoreEntries[index].Amount >= amounts[i]) { //add to the list to return stores.Add(store.StoreEntries[index]); //record the amount to consume, so if the operation is a success, the store entry will perform the consumption store.StoreEntries[index].ToConsume = amounts[i]; //flag this entry as found foundentries[i] = true; //go on to the next type break; } } } return(stores); }
//this is used to withdraw based on a particular store entry, and specified parameters public static Item WithdrawByEntryType(Container pack, Type entrytype, int amount, object[] parameters) { //check if there are any BaseStoreKey or MasterItemStoreKey objects in the caster's backpack Item[] keysources = pack.FindItemsByType(new Type[] { typeof(BaseStoreKey), typeof(MasterItemStoreKey) }); if (keysources == null || amount == 0) { return(null); } //go thru the list of found objects foreach (Item key in keysources) { //utilizes IItemStoreObject interface function, defined by keys if (key is IItemStoreObject) { //scan this object for any usable candidates to withdraw from StoreEntry entry = ((IItemStoreObject)key).FindEntryByEntryType(entrytype, amount, parameters); if (entry != null) { Item item = entry.Withdraw(ref amount, true); entry.RefreshParentGump(); pack.AddItem(_LastWithdrawn); return(item); } } } return(null); }
static bool addData(StoreEntry entry, bool overwrite = false) { XmlNode duplicated = null; foreach (XmlNode node in dataStore.DocumentElement.ChildNodes) { if (node.Attributes["key"].Value == entry.key) { duplicated = node; break; } } if (!overwrite && duplicated != null) { return(false); } if (duplicated != null) { dataStore.DocumentElement.RemoveChild(duplicated); } XmlNode n = dataStore.CreateElement("Data"); XmlAttribute attr = dataStore.CreateAttribute("key"); attr.Value = entry.key; //n.Attributes = new XmlAttributeCollection(); n.Attributes.Append(attr); attr = dataStore.CreateAttribute("version"); attr.Value = entry.version.ToString(); n.Attributes.Append(attr); attr = dataStore.CreateAttribute("value"); attr.Value = entry.value; n.Attributes.Append(attr); dataStore.DocumentElement.AppendChild(n); dataStore.Save(dataStoreFile); InitStore(); return(true); }
/// <summary> /// called when processing a valid request message and then verify state, discovery or enrollment /// </summary> /// <param name="req"></param> public static HttpResponse VerifyRequest(HttpMessage req) { HttpResponse ret = null; if (req == null) { testSite.Assert.Fail("Not receive any request"); } if (!(req is HttpRequest)) { testSite.Assert.Fail("only expect HTTP request"); } HttpRequest r = (HttpRequest)req; switch (r.Method) { case HttpRequest.HttpMethod.PUT: { if (r.RequestUrl.Path.ToLower().StartsWith(Constraints.StoreUrl.ToLower() + "/")) { StoreEntry entry = (StoreEntry)JsonUtility.DeserializeJSON(r.Body, typeof(StoreEntry)); if (addData(entry, true)) { return(createSuccess()); } else { return(createInternalError()); } } } break; case HttpRequest.HttpMethod.GET: { if (r.RequestUrl.Path.ToLower() == Constraints.StoreUrl.ToLower()) { StoreEntry[] array = getExternalEntries().ToArray(); ret = createSuccess(); ret.Body = JsonUtility.SerializeJSON(array); ret.SetHeaderField(System.Net.HttpResponseHeader.ContentLength, ret.Body.Length.ToString()); return(ret); } else if (r.RequestUrl.Path.ToLower() == Constraints.FederationMetadataUrl.ToLower()) { } else if (r.RequestUrl.Path.ToLower() == Constraints.GetSTSConfigurationUrl.ToLower()) { ret = new HttpResponse(System.Net.HttpStatusCode.OK); STSConfiguration conf = createValidStsConfigurationResponse(); ret.Body = JsonUtility.Encode(conf.ToString()); ret.SetHeaderField(System.Net.HttpResponseHeader.ContentLength, ret.Body.Length.ToString()); return(ret); } else if (r.RequestUrl.Path.ToLower() == Constraints.ProxyTrustUrl.ToLower()) { StoreEntry entry = getData(TrustIdentifierRecord); if (entry == null) { return(createNotFound()); } else { ret = new HttpResponse(System.Net.HttpStatusCode.OK); ProxyRelyingPartyTrust pt = new ProxyRelyingPartyTrust(); pt.Identifier = entry.value; ret.Body = pt.ToString(); return(ret); } } else if (r.RequestUrl.Path.ToLower() == Constraints.StoreUrl.ToLower()) { } else if (r.RequestUrl.Path.ToLower() == Constraints.RelyingPartyTrustUrl.ToLower()) { StoreEntry entry = getData(managedAppsRecord); if (entry == null) { return(createNotFound()); } else { ret = createSuccess(); ret.Body = entry.value; ret.SetHeaderField(System.Net.HttpResponseHeader.ContentLength, ret.Body.Length.ToString()); return(ret); } } else if (r.RequestUrl.Path.ToLower().StartsWith(Constraints.StoreUrl.ToLower() + "/")) { StoreEntry entry = getData(r.RequestUrl.Path.ToLower().Substring((Constraints.StoreUrl.ToLower() + "/").Length)); if (entry == null) { return(createNotFound()); } else { ret = createSuccess(); ret.Body = entry.ToString(); ret.SetHeaderField(System.Net.HttpResponseHeader.ContentType, "application/json;charset=UTF-8"); ret.SetHeaderField(System.Net.HttpResponseHeader.ContentLength, ret.Body.Length.ToString()); return(ret); } } } break; case HttpRequest.HttpMethod.POST: { if (r.RequestUrl.Path.ToLower() == Constraints.EstablishTrustUrl.ToLower()) { StoreEntry entry = getData(TrustCertificateRecord); if (entry != null) { testSite.Assert.Fail("Trust already established"); return(createInternalError()); } EstablishTrustRequest dict = (EstablishTrustRequest)JsonUtility.DeserializeJSON(r.Body, typeof(EstablishTrustRequest)); entry = new StoreEntry(); entry.key = TrustCertificateRecord; entry.version = -1; entry.value = dict.SerializedTrustCertificate; if (addData(entry)) { return(createSuccess()); } } else if (r.RequestUrl.Path.ToLower().Contains(Constraints.RelyingPartyTrustUrl.ToLower() + "/")) { return(createSuccess()); } else if (r.RequestUrl.Path.ToLower() == Constraints.ProxyTrustUrl.ToLower()) { StoreEntry entry = getData(TrustIdentifierRecord); if (entry != null) { return(createInternalError()); } ProxyRelyingPartyTrust dict = (ProxyRelyingPartyTrust)JsonUtility.DeserializeJSON(r.Body, typeof(ProxyRelyingPartyTrust)); entry = new StoreEntry(); entry.key = TrustIdentifierRecord; entry.version = -1; entry.value = dict.Identifier; if (addData(entry)) { return(createSuccess()); } } else if (r.RequestUrl.Path.ToLower() == Constraints.StoreUrl.ToLower()) { } else if (r.RequestUrl.Path.ToLower().StartsWith(Constraints.StoreUrl.ToLower() + "/")) { StoreEntry entry = (StoreEntry)JsonUtility.DeserializeJSON(r.Body, typeof(StoreEntry)); if (addData(entry)) { HttpResponse tosend = createSuccess(); // Yuqing: MUST set bellows!!! tosend.SetHeaderField(System.Net.HttpResponseHeader.ContentLength, "0"); tosend.SetHeaderField(System.Net.HttpResponseHeader.ContentType, "text/html;charset=UTF-8"); return(tosend); } else { return(createInternalError()); } } } break; default: testSite.Assert.Fail("Unsupported HTTP method"); break; } //testSite.Assert.IsNotNull(ret, "Request is handled"); return(ret); }
public void Deserialize(GenericReader reader) { int version = reader.ReadInt(); switch (version) { case 3: { LockWithdrawalAmount = reader.ReadBool(); goto case 2; } case 2: { Insured = reader.ReadBool(); goto case 1; } //case 1: added reference for loottype of parent object, as well as columns to display on gump case 1: { LootType = (LootType)reader.ReadInt(); DisplayColumns = reader.ReadInt(); goto case 0; } case 0: default: { Label = reader.ReadString(); Dynamic = reader.ReadBool(); OfferDeeds = reader.ReadBool(); WithdrawAmount = reader.ReadInt(); MinWithdrawAmount = reader.ReadInt(); int entrycount = reader.ReadInt(); //read in the active items if (entrycount > 0) { for (int i = 0; i < entrycount; i++) { //dynamically create store entries, ore derived ones, based on the type name stored in the serial data, then add it to the serial data reader //WARNING... this is very delicate!! if an improper type name was saved to the serial data (eg. if a tool or resource used to belong to a tool, and was removed from the shard) then an exception will be thrown here. //be sure to remove any and all tool types from keys, and cycle a world load/save before taking that class out StoreEntry entry = (StoreEntry)Activator.CreateInstance(ScriptCompiler.FindTypeByName(reader.ReadString()), new object[] { reader }); //register this store with the entry for refresh purposes entry.Store = this; StoreEntries.Add(entry); } } //read in the expelled items entrycount = reader.ReadInt(); if (entrycount > 0) { for (int i = 0; i < entrycount; i++) { StoreEntry entry = (StoreEntry)Activator.CreateInstance(ScriptCompiler.FindTypeByName(reader.ReadString()), new object[] { reader }); //register this store with the entry for refresh purposes entry.Store = this; ExpelStoreEntries.Add(entry); } } break; } } } //deserialize
//this synchronizes the item store with a specified list of item entries. this is done to allow a scripter to on-the-fly //modify the contents of any object containing an item store without having to manually reorganize the data entries of all //instanced objects in the world save data public void SynchronizeStore(List <StoreEntry> synchentries) { //Idea: stick current active store entry list in a temporary location, and rebuild the list using the //synchentries list data. Pull amount info from the temporary list (if it exists there) and remove that entry //from the temporary list. Finally, put any leftover entries in the temporary list into the expel list, to //be claimed externally the next time the device implementing this list is used. //store the current world loaded list into a temporary list List <StoreEntry> templist = StoreEntry.CloneList(_StoreEntries); //clear the current list so it's ready to be written to _StoreEntries = new List <StoreEntry>(); //begin generating new list based on synch entries parameter foreach (StoreEntry entry in synchentries) { //use clone constructor StoreEntry newentry = entry.Clone(); //find a matching item entry in the temporary list int matchingindex = StoreEntry.IndexOfType(templist, entry.Type); if (matchingindex > -1) { //special treatment: if the entry is a list entry, then transfer the contained list too if (entry is ListEntry && templist[matchingindex] is ListEntry) { //transfer over a clone copy of all item list entries ((ListEntry)entry).CloneItemListEntries((ListEntry)templist[matchingindex]); } //special treatment: if the entry is a stash entry, then transfer the contained list too else if (entry is StashEntry && templist[matchingindex] is StashEntry) { //transfer over a clone copy of all the item stash entries ((StashEntry)entry).CloneStashListEntries((StashEntry)templist[matchingindex]); } else { //transfer over the amount into the new listing entry.Amount = templist[matchingindex].Amount; } templist.RemoveAt(matchingindex); } else { } //add this to the finished product list _StoreEntries.Add(entry); //register entry with this store for refresh purposes entry.Store = this; } //finally, store the leftovers in the expel list foreach (StoreEntry entry in templist) { if (entry.Amount > 0) //note, this will automatically ignore all column separators { int matchingindex = StoreEntry.IndexOfType(ExpelStoreEntries, entry.Type); if (matchingindex > -1) { //append amount to existing entry in expel list ExpelStoreEntries[matchingindex].Amount += entry.Amount; } else { //add new entry to the expel list ExpelStoreEntries.Add(entry); } } } RefreshEntryHeight(); }
//code to finish adding an item - accessed by the add item target public void AddItem(Mobile from, object targeted) { if (from != null && !CanUse(from)) { from.SendMessage("You no longer can use that"); return; } //keep track of the item Item item = null; //keep track of the deed if it's a commodity deeds Item deed = null; int entryindex; if (!(targeted is Item)) { if (from != null) { from.SendMessage("this only works on items."); } return; } item = (Item)targeted; if (from != null && !item.IsChildOf(from.Backpack)) { BankBox box = from.FindBankNoCreate(); if (box == null || !item.IsChildOf(box)) { from.SendMessage("you can only add items from your backpack or bank box"); return; } } //Handle commodity deed insertion if (item is CommodityDeed) { if (((CommodityDeed)item).Commodity == null) { if (from != null) { from.SendMessage("there is nothing to add in that commodity deed."); } return; } //store the deed reference deed = item; //reference the commodity within the deed item = ((CommodityDeed)item).Commodity; } //this uses the overloadable comparison for the appropriate store entries, so that custom store entries //can provide custom comparisons with items through their Match() methods entryindex = StoreEntry.IndexOfItem(_StoreEntries, item, true); if (entryindex == -1) { if (from != null) { from.SendMessage("that cannot be stored in this."); } return; } //reference the item store entry StoreEntry entry = _StoreEntries[entryindex]; if (!entry.Add(item)) { if (from != null) { from.SendMessage("that quantity cannot fit in this."); } return; } //don't delete items that are stuck in a stash list if (!(entry is StashEntry)) { //delete the item after if (deed != null) { deed.Delete(); } else { entry.AbsorbItem(item); } } //start next add and give another cursor if (from != null) { AddItem(from); //resend the gump after it's all done if (!ItemStoreGump.RefreshGump(from)) { //send a new gump if there's no existing one up from.SendGump(new ItemStoreGump(from, this)); } } }
public void RefreshEntryHeight() { _EntryHeight = StoreEntry.GetTotalHeight(StoreEntries); }
//this adds the listing of all item stores protected bool AddStoreListing() { if (_Store == null || _Store.Count == 0) { return(true); } if (_Store.OfferDeeds && ShowDeeds()) { for (int i = 0; i < _Store.DisplayColumns; i++) { AddItem(_WithdrawDeedColumn - 20 + i * ColumnWidth, _Y, 0x14F0, 71); //Commodity deed artwork } _Y += 30; } //save the current height to determine when to switch to a new column int tempy = _Y; //used for writing more than one column of contents int xoffset = 0; for (int i = _ListingStart; i < _Store.StoreEntries.Count; i++) { StoreEntry entry = _Store.StoreEntries[i]; //check if we need a new line if (_Y - tempy >= _ListingHeight || entry is ColumnSeparationEntry) { xoffset += ColumnWidth; _Y = tempy; //if you've filled the page, then break if (xoffset >= _Store.DisplayColumns * ColumnWidth) { break; } //if this is a forced new line, don't process it any further. go on to next entry if (entry is ColumnSeparationEntry) { continue; } } //draw the artwork Item item = entry.GetModel(); //if there was a problem obtaining the graphic if (item == null) { _Owner.SendMessage("Error: " + entry.ErrorMessage); return(false); } //add a graphic of the item AddItem(entry.X + xoffset + _ItemColumn, entry.Y + _Y, item.ItemID, item.Hue); //add the name. Special treatment: if the entry is a ListEntry, then add a "..." to signify more info on inner gump AddLabel(xoffset + _ItemNameColumn, _Y, 0x486, entry.Name + ((entry is ListEntry) ? "..." : "")); //add the amount AddLabel(xoffset + _AmountColumn, _Y, 0x480, entry.Amount.ToString()); //add the standard withdrawl button, indexed with i, and offset of 1 //the offset of 1 is used since response ID # 0 is used for right-clicking //on the gump to close it. so all button values have to be above 0 //to distinguish between a right-click and a button press //button graphic is changed by having an overridden buttonID stored in the storeentry type AddButton(xoffset + _WithdrawColumn + entry.ButtonX, _Y + entry.ButtonY, entry.ButtonID, entry.ButtonID + 1, i + 1, GumpButtonType.Reply, 0); //if the stuff can be put in a commodity deed.. if (_Store.OfferDeeds && entry is ResourceEntry && ((ResourceEntry)entry).Deedable) { //then add a button to withdraw into commodity deed, indexed with i + _Store.StoreEntries.Count + 1 //(where _Store.StoreEntries.Count is used in the response code to flag that the user is trying //to withdraw using a commodity deed) and offset of 1 AddButton(xoffset + _WithdrawDeedColumn + entry.ButtonX, _Y + entry.ButtonY, 0x4B9, 0x4B9, _Store.StoreEntries.Count + i + 1, GumpButtonType.Reply, 0); } _Y += entry.Height; //clean up the instanced item so it doesn't populate the shard with bogus items item.Delete(); } return(true); }
public void SetUp() { _mocks = new MockRepository(); _storeEntry = _mocks.StrictMock<StoreEntry>(); _deleteEntries = _mocks.StrictMock<DeleteEntries>(); _renameResource = _mocks.StrictMock<RenameResource>(); _retrieveAllEntries = _mocks.StrictMock<RetrieveAllEntries>(); _retrieveEntriesForResource = _mocks.StrictMock<RetrieveEntriesForResource>(); _retrieveEntriesForSubject = _mocks.StrictMock<RetrieveEntriesForSubject>(); }
public static bool CraftWithdraw(Container pack, Type[] types, int amount, bool getamountonly) { //check if there are any BaseStoreKey or MasterItemStoreKey objects in the caster's backpack Item[] keysources = pack.FindItemsByType(new Type[] { typeof(BaseStoreKey), typeof(MasterItemStoreKey) }); if (keysources == null || types == null || amount == 0) { return(false); } //go thru the list of found objects foreach (Item key in keysources) { //utilizes IItemStoreObject interface function, defined by keys if (key is IItemStoreObject) { //scan this object for any usable candidates to withdraw from StoreEntry entry = ((IItemStoreObject)key).FindConsumableEntry(types, amount); if (entry != null) { if (getamountonly) { _LastAmountCount = entry.Amount; } else if (entry.Amount < amount) { //don't do anything if there's not enough to work from return(false); } else { //if a valid entry was found, withdraw it to the container Console.WriteLine("trying to withdraw " + amount.ToString()); //doesn't work properly with unstackable items //store the amount that needs to be withdrawn, and reset the amount that has been withdrawn int amounttowithdraw = amount; int amountwithdrawn = 0; //keep withdrawing until the desired amount has been taken out while (amountwithdrawn < amounttowithdraw) { amount = amounttowithdraw - amountwithdrawn; _LastWithdrawn = entry.Withdraw(ref amount); amountwithdrawn += amount; //if for some reason none was taken out, then exit if (amount == 0) { return(false); } pack.AddItem(_LastWithdrawn); } entry.RefreshParentGump(); } return(true); } } } //if nothing was found, return false return(false); } //static CraftWithdraw
public virtual void Buy(int index) { InputModeDisplay.instance.CloseConfirmation(); GameplayManager gm = GameplayManager.instance; if (index < piles.Count && CanBuy(index)) { switch (costType) { case Store.Type.attack: gm.attack -= piles[index].price; break; case Store.Type.coin: gm.coin -= piles[index].price; break; case Store.Type.hammers: gm.hammers -= piles[index].price; break; case Store.Type.science: gm.science -= piles[index].price; break; } Buyable bought = piles[index].elements[0]; StoreEntry entry = piles[index]; entry.price = piles[index].basePrice; piles[index] = entry; RemoveElement(bought); GameplayManager.instance.StartCoroutine(bought.Buy()); } else if (partialBuy && index < piles.Count) { switch (costType) { case Store.Type.attack: { StoreEntry entry = piles[index]; entry.price -= gm.attack; piles[index] = entry; gm.attack = 0; break; } case Store.Type.coin: { StoreEntry entry = piles[index]; entry.price -= gm.coin; piles[index] = entry; gm.coin = 0; break; } case Store.Type.hammers: { StoreEntry entry = piles[index]; entry.price -= gm.hammers; piles[index] = entry; gm.hammers = 0; break; } case Store.Type.science: { StoreEntry entry = piles[index]; entry.price -= gm.science; piles[index] = entry; gm.science = 0; break; } } } }
//the master withdraw method public void WithdrawItem(Mobile from, int amount, int entryindex, bool makedeed, bool resend) { StoreEntry entry = null; try { entry = _StoreEntries[entryindex]; } catch { from.SendMessage("invalid selection pressed."); return; } //make sure making deeds is being offered with this bitmask makedeed &= OfferDeeds; //special handling - for a ListEntry object, hitting withdraw is not intended to remove the object, but rather //bring up a gump showing the list contained within the ListEntry if (entry is ListEntry) { from.SendGump(new ListEntryGump(from, (ListEntry)entry)); return; } //special handling - for a StashEntry object, hitting withdraw will bring up a gump showing the stash contained //within the StashEntry if (entry is StashEntry) { from.SendGump(new StashEntryGump(from, (StashEntry)entry)); return; } if (entry.Amount > 0) { //check if they can afford a commodity deed if (makedeed && resend && !Banker.Withdraw(from, 5)) { from.SendMessage("you must have at least 5 gold in your bank to extract the resource into a commodity deed"); return; } if (BaseStoreKey.EmptyContents && entry.RequiresRecipient) { Item recipient = entry.FindRecipient(from); if (recipient != null) { if (entry.WithdrawTo(ref WithdrawAmount, recipient) == null) { from.SendMessage("Cannot withdraw that for some reason!"); return; } } else { from.SendMessage("You do not have a container to store that."); return; } } else { Item item = entry.Withdraw(ref WithdrawAmount, makedeed); if (item == null) { from.SendMessage("there was an error creating that item. Please page a GM!"); return; } from.AddToBackpack(item); } } else { from.SendMessage("you don't have any of that"); } }