public bool IngestBurden(Burden burden, CharacterBurdenManager sender, CharacterBurdenManager receiver) { if (d_heldBurdens.ContainsKey(burden.category)) { //this category is already held //an instance of this type is already held, Process it and add it to the list. Burden ReceiverTintedBurden = ReceiverTintBurden(burden, sender, receiver); Burden IngestTintedBurden = IngestTintBurden(burden, sender, receiver); d_heldBurdens[burden.category].Add(IngestTintedBurden); } else { d_heldBurdens.Add(burden.category, new List <Burden>()); //make the new category Burden ReceiverTintedBurden = ReceiverTintBurden(burden, sender, receiver); //tint by receiver (character ingest action) Burden IngestTintedBurden = IngestTintBurden(burden, sender, receiver); //tint by ingest (burden ingest action) d_heldBurdens[burden.category].Add(burden); //add to receiver inventory //this is a new burden we have not received yet. make a new info, new list, and add to it. } //a character should only ever have one copy of any type of burden. adding to that type increases the count in it. //modifiedBurden.OwnerChangeNotice(this, true); BurdensCollectionChanged(); //return true if the addition was compatible with the container, after adding. return(true); }
public static bool TransferBurden(Burden burden,CharacterBurdenManager sender, CharacterBurdenManager receiver) { //burden.BurdenPreSend(sender); //burden prepares for dispatch while inside first container. //Strongly consider verifying the ability for sender and receiver to "pre-approve" the transfer. As it is very hard to undo. //it would be nice to get a reason for the rejection, perhaps return some send/receive data on prevalidate. if(!PrevalidateTransaction(burden, sender, receiver)) { return false; } bool SendSuccess = sender.burdenInventory.DispatchBurden(burden,sender.burdenInventory,receiver.burdenInventory); bool ReceiveSuccess = receiver.AddBurden(burden, sender, receiver); if(SendSuccess && ReceiveSuccess) { Debug.Log("Burden transaction complete"); return true; } else { Debug.Log("Burden transaction failure to send from " + sender.burdenInventory.ContainerName + " to " + receiver.burdenInventory.ContainerName + " of type " + burden.category.ToString()); return false; } }
public static bool PrevalidateTransaction(Burden burden, CharacterBurdenManager sender, CharacterBurdenManager receiver) { //if receiver is null, this is auto-true, as we are destroying the burden bool canReceive = true; //if sender is null, this is auto-true, as this is a new burden from the world.; bool canSend = true; if (sender != null) { if (!sender.canSendBurdens) { canSend = false; } } if(receiver!=null) { if(!receiver.canReceiveBurdens) { canReceive = false; } } if (burden.duplicateRule == Burden.CloneDuplicateRule.rejectAllDuplicateRequests && receiver.burdenInventory.d_heldBurdens.ContainsKey(burden.category)) { Debug.Log("burden duplicate disallowed by configuration of parent burden. (category type was already held)"); //this is not necessarily a failure, as some burdens may accumulate while others cannot. Abort the transaction. //be wary, this can infinite loop if paired with an aggressive queue. //let the sender know their attempt was rejected, perhaps even add more flavorful data later. sender.BurdenSendRejected(TransactionRejectionReasons.DuplicatesPrevented, sender, receiver, burden); receiver.BurdenReceiveRejected(TransactionRejectionReasons.DuplicatesPrevented, sender, receiver, burden); return false; } if (!canSend) { Debug.LogWarning("A burden transaction was rejected by SENDER : " + sender.burdenInventory.ContainerName); sender.BurdenSendRejected(TransactionRejectionReasons.CharacterUnableToSend, sender, receiver,burden); receiver.BurdenReceiveRejected(TransactionRejectionReasons.CharacterUnableToSend, sender, receiver,burden); BurdenTransactionFailedLog(burden, sender, receiver, false); return false; } if (!canReceive) { Debug.LogWarning("A burden transaction was rejected by RECEIVER : " + receiver.burdenInventory.ContainerName); sender.BurdenSendRejected(TransactionRejectionReasons.CharacterUnableToReceive, sender, receiver, burden); receiver.BurdenReceiveRejected(TransactionRejectionReasons.CharacterUnableToReceive, sender, receiver, burden); BurdenTransactionFailedLog(burden, sender, receiver, false); return false; } return true; }
Burden IngestTintBurden(Burden burden, CharacterBurdenManager sender, CharacterBurdenManager receiver) { //Lets the burden's ingest behavior act, with reference to the sender and receiver so the burden can do things to them. if (sender != null) { burden.BurdenIngestAction(sender.burdenInventory, this); } else { burden.BurdenIngestAction(null, this); } return(burden); }
Burden ReceiverTintBurden(Burden burden, CharacterBurdenManager sender, CharacterBurdenManager receiver) { //tint based on receiving behaviors of the receiving inventory BurdenProcess receiverOperation = BurdenTools.GetBurdenProcessReceiver(receiverType); if (sender != null) { burden = receiverOperation(burden, sender.burdenInventory, receiver.burdenInventory); } else { burden = receiverOperation(burden, null, receiver.burdenInventory); } return(burden); }
public bool DispatchBurden(Burden burden, BurdenInventory sender, BurdenInventory receiver) { //tint by sender BurdenProcess senderOperation = BurdenTools.GetBurdenProcessSender(senderType); Burden modifiedBurden = senderOperation(burden, this, receiver); //tint by parentburden's pre-send action while still in sender inventory modifiedBurden.BurdenSendAction(burden, sender, receiver); d_heldBurdens[modifiedBurden.category].Remove(modifiedBurden); modifiedBurden.OwnerChangeNotice(burden, sender, false); BurdensCollectionChanged(); burden.BurdenPostSend(burden, this); return(true); }
public void DissolveBurden(Burden burden, bool isSilent) { if (d_heldBurdens.ContainsKey(burden.category)) { if (!isSilent) { burden.BurdenPreDissolve(this); } d_heldBurdens[burden.category].Remove(burden); BurdensCollectionChanged(); if (!isSilent) { burden.BurdenPostDissolve(this); } } else { Debug.LogWarning("no burden in the requested category to dissolve : " + burden.category.ToString()); } }
public static List<BurdenInventory> GetOwnersOfBurdenType(Burden b) { Debug.LogError("shit aint done"); return null; }
public static int GetNumInstancesHeld(Burden b,BurdenInventory i) { Debug.LogError("shit aint done"); return 0; }
public static Burden M21BurdenReceiver(Burden burden, BurdenInventory sender, BurdenInventory receiver) { Debug.Log("Burden modified by M21's receiver"); return burden; }
//this overload is used when a sender does not exist. it will dispatch null to the various methods instead. public bool IngestBurden(Burden burden, CharacterBurdenManager receiver) { return(IngestBurden(burden, null, receiver)); }
public static Burden SlaughterBurdenReceiver(Burden burden, BurdenInventory sender, BurdenInventory receiver) { Debug.Log("Burden modified by Slaughters's receiver"); return burden; }
public static Burden RaviBurdenReceiver(Burden burden, BurdenInventory sender, BurdenInventory receiver) { Debug.Log("Burden modified by Ravi's receiver"); burden.AdjustFear(-1); return burden; }
} //burden is dispatched, the sender tints the burden here. public virtual void BurdenPostSend(Burden burden, BurdenInventory origin) { } //when burden is sent to another entity, after the sender has modified it.
public virtual void OwnerChangeNotice(Burden burden, BurdenInventory owner, bool acquiring) { //what happens when a burden changes hands? }
public virtual void BurdenSendAction(Burden burden, BurdenInventory origin, BurdenInventory target) { } //burden is dispatched, the sender tints the burden here.
public static void BurdenTransactionFailedLog(Burden burden, CharacterBurdenManager sender, CharacterBurdenManager receiver, bool queue = false) { //this is for error debugging, and not behavior. Debug.LogWarning("A burden transaction failed between " + sender.burdenInventory.ContainerName + " and " + receiver.burdenInventory.ContainerName); }
//BURDEN SENDER BEHAVIORS //BURDEN SENDER BEHAVIORS //BURDEN SENDER BEHAVIORS public static Burden DEFAULTBurdenSender(Burden burden,BurdenInventory sender, BurdenInventory receiver) { //the default sender does nothing. The burden is transmitted unmodified. Debug.Log("No modifier applied to Burden Sent"); return burden; }
public static Burden SlaughterBurdenSender(Burden burden, BurdenInventory sender, BurdenInventory receiver) { Debug.Log("Slaughter modifier applied to Burden Sent"); return burden; }
public static Burden RaviBurdenSender(Burden burden, BurdenInventory sender, BurdenInventory receiver) { Debug.Log("Ravi modifier applied to Burden Sent"); return burden; }