public bool TryGetTotalChange(ChangeDestination cd, out TotalChange tc) { lock (effectLock) { return(destToTotalChange.TryGetValue(cd, out tc)); } }
partial void pCTC_CDStatic(BaseEffectHandler eh, TotalChange tc) { try { ChangeInitInfo info; if (!ValidateChangeInit(ChangeType.Vob_CDStatic_Set, out info)) { return; } // use default or value from last Change bool val = Default_CDStatic; if (tc.Components.Count > 0) { val = (bool)tc.Components.Last().GetParameters()[0]; } var finalChange = Change.Create(info, new List <object>() { val }); tc.SetTotal(finalChange); } catch (Exception ex) { MakeLogError("Error while caclulating TotalChange via pCTC_CDStatic: " + ex); } }
partial void pCTC_VobType(BaseEffectHandler eh, TotalChange tc) { try { // stop here when there are no Changes to process if (tc.Components.Count < 1) { return; } ChangeInitInfo info; if (!ValidateChangeInit(ChangeType.Vob_VobType_Set, out info)) { return; } // TO DO: only change VobType if the linked object is actually able to !!! // last entry counts var finalChange = Change.Create(info, new List <object>() { tc.Components[tc.Components.Count - 1] }); tc.SetTotal(finalChange); } catch (Exception ex) { MakeLogError("Error while caclulating TotalChange via pCTC_VobType: " + ex); } }
partial void pCTC_Material(BaseEffectHandler eh, TotalChange tc) { try { ChangeInitInfo info; if (!ValidateChangeInit(ChangeType.Item_Material_Set, out info)) { return; } ItemMaterials material; if (tc.Components.Count < 1) { material = Default_Material; } else { // last entry counts material = (ItemMaterials)tc.Components[0].GetParameters()[0]; } var finalChange = Change.Create(info, new List <object>() { material }); tc.SetTotal(finalChange); } catch (Exception ex) { MakeLogError("Error while caclulating TotalChange via pCTC_Material: " + ex); } }
public static void WriteTotalChange(PacketWriter pw, ChangeDestination cd, TotalChange tc) { var total = tc.GetTotal(); var param = total.GetParameters(); // return preemtively when there is nothing to send if (total == null) { return; } // write head TypeToRW[typeof(ChangeDestination)].Write(pw, cd); TypeToRW[typeof(ChangeType)].Write(pw, total.GetChangeType()); TypeToRW[typeof(int)].Write(pw, param.Count); // write parameters Type t; ReadWriteObject rw; for (int i = 0; i < param.Count; i++) { t = param[i].GetType(); if (TypeToRW.TryGetValue(t, out rw)) { rw.Write(pw, param[i]); } } }
public static bool TryGetTotalChange(BaseEffectHandler effectHandler, ChangeDestination changeDest, out TotalChange totalChange) { totalChange = null; if (effectHandler.TryGetTotalChange(changeDest, out totalChange)) { return(true); } return(false); }
partial void pATC_Name(BaseEffectHandler eh, TotalChange tc) { // assuming that the EffectName is only set --> set it in the respective effect of each change try { List <Change> components = tc.Components; for (int c = 0; c < components.Count; c++) { components[c].GetEffect().SetEffectName((string)components[c].GetParameters()[0]); } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via ATC_Name: " + ex); } }
partial void pATC_CDStatic(BaseEffectHandler eh, TotalChange tc) { try { var linkedObj = eh.Host; if (linkedObj is VobDef) { var vobDef = linkedObj as VobDef; vobDef.CDStatic = (bool)tc.GetTotal().GetParameters()[0]; } else if (linkedObj is VobInst) { // TO DO: add similar code as for VobDef when VobSystem supports it } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via pATC_CDStatic: " + ex); } }
public string GetStats() { string s = string.Empty; if (domain.Count() == 0) { return(s); } s += "Name: " + Name + "\n"; s += "Percent change: " + PercentChange.ToString() + "\n"; s += "Range: " + TotalChange.ToString() + "\n"; s += "Start date: " + StartDate.ToShortDateString() + "\n"; s += "End date: " + EndDate.ToShortDateString() + "\n"; s += "Start val: " + StartVal.ToString() + "\n"; s += "End val: " + EndVal.ToString() + "\n"; return(s); }
partial void pATC_Material(BaseEffectHandler eh, TotalChange tc) { try { var linkedObj = eh.Host; if (linkedObj is ItemDef) { var vobDef = linkedObj as ItemDef; vobDef.Material = (ItemMaterials)tc.GetTotal().GetParameters()[0]; } else if (linkedObj is ItemInst) { var vobInst = linkedObj as ItemInst; // TO DO when there is the possiblity to change the name in VobSystem } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via pATC_Material: " + ex); } }
partial void pATC_CodeName(BaseEffectHandler eh, TotalChange tc) { try { var linkedObj = eh.Host; if (linkedObj is VobDef) { var vobDef = linkedObj as VobDef; vobDef.CodeName = (string)tc.GetTotal().GetParameters()[0]; } else if (linkedObj is VobInst) { var vobInst = linkedObj as VobInst; // ??? TO DO if codeName should be changable for a VobInst } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via ATC_CodeName: " + ex); } }
public static TotalChange ReadTotalChange(PacketReader pr) { var tc = new TotalChange(); // head var changeDest = (ChangeDestination)TypeToRW[typeof(ChangeDestination)].Read(pr); var changeType = (ChangeType)TypeToRW[typeof(ChangeType)].Read(pr); var paramLength = (int)TypeToRW[typeof(int)].Read(pr); // parameters List <object> param = new List <object>(paramLength); // generate the simplified TotalChange with only a total-value, no components var total = Change.Create(changeType, param); tc.SetTotal(total); return(tc); }
partial void pATC_GlobalID(BaseEffectHandler eh, TotalChange tc) { try { Effect effect; string globalID; var components = tc.Components; int i; for (i = 0; i < components.Count; i++) { effect = components[i].GetEffect(); globalID = (string)components[i].GetParameters()[0]; if (globalID != null) { Effect.AddGlobalEffect(globalID, effect); } } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via pATC_GlobalID: " + ex); } }
// perhaps make this protected and adding a slower, less direct method for Effects to use ??? public void AddToTotalChanges(Change change, DateTime effectSubDate, DateTime changeSubDate) { List <ChangeDestination> destinations; TotalChange tc; lock (effectLock) { if (!changeTypeToDestinations.TryGetValue(change.GetChangeType(), out destinations)) { return; } for (int d = 0; d < destinations.Count; d++) { if (destToTotalChange.TryGetValue(destinations[d], out tc)) { // if a TotalChange already exists, simply add the Change to it tc.AddChange(change, effectSubDate, changeSubDate); } else { // if not present, create the TotalChange and then add the Change to it CalculateTotalChange calcTotal; ApplyTotalChange applyTotal; if (destToCalcTotal.TryGetValue(destinations[d], out calcTotal) && destToApplyTotal.TryGetValue(destinations[d], out applyTotal)) { tc = new TotalChange(); tc.SetCalcFunction(calcTotal); tc.SetApplyFunction(applyTotal); tc.AddChange(change, effectSubDate, changeSubDate); } else { MakeLogError("Requested non-registered ChangeDestination in AddToTotalChanges: " + destinations[d]); } } } } }
partial void pATC_Parent(BaseEffectHandler eh, TotalChange tc) { try { Effect effect; Effect parent; string parentGlobalID; List <Change> components = tc.Components; for (int c = 0; c < components.Count; c++) { effect = components[c].GetEffect(); parentGlobalID = (string)components[c].GetParameters()[0]; if (!Effect.TryGetGlobalEffect(parentGlobalID, out parent)) { MakeLogWarning("Did not find effect behind globalID " + parentGlobalID + " to add as parent effect in ATC_Parent"); } effect.AddParent(parent); } } catch (Exception ex) { MakeLogError("Error while applying TotalChange via pATC_Parent: " + ex); } }
public void ATC_GlobalID(BaseEffectHandler eh, TotalChange tc) { pATC_GlobalID(eh, tc); }
partial void pATC_GlobalID(BaseEffectHandler eh, TotalChange tc);
partial void pATC_Clock_Time(BaseEffectHandler eh, TotalChange tc);
public void CTC_Clock_Time(BaseEffectHandler eh, TotalChange tc) { pCTC_Clock_Time(eh, tc); }
public void ATC_Clock_Rate(BaseEffectHandler eh, TotalChange tc) { pATC_Clock_Rate(eh, tc); }
partial void pATC_PermanentFlag(BaseEffectHandler eh, TotalChange tc);
partial void pATC_Clock_IsRunning(BaseEffectHandler eh, TotalChange tc);
partial void pATC_Name(BaseEffectHandler eh, TotalChange tc);
partial void pATC_Parent(BaseEffectHandler eh, TotalChange tc);
public void ATC_Parent(BaseEffectHandler eh, TotalChange tc) { pATC_Parent(eh, tc); }
public void ATC_Clock_IsRunning(BaseEffectHandler eh, TotalChange tc) { pATC_Clock_IsRunning(eh, tc); }
public void ATC_PermanentFlag(BaseEffectHandler eh, TotalChange tc) { pATC_PermanentFlag(eh, tc); }
partial void pCTC_Clock_Rate(BaseEffectHandler eh, TotalChange tc);
public void ATC_Name(BaseEffectHandler eh, TotalChange tc) { pATC_Name(eh, tc); }
public void ATC_Material(BaseEffectHandler eh, TotalChange tc) { pATC_Material(eh, tc); }