public bool TryGetTotalChange(ChangeDestination cd, out TotalChange tc) { lock (effectLock) { return(destToTotalChange.TryGetValue(cd, out tc)); } }
public bool TryGetEffects(ChangeDestination changeDestination, out List <Effect> effects) { lock (effectLock) { return(destToEffects.TryGetValue(changeDestination, out effects)); } }
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 DestInitInfo(ChangeDestination changeDestination, List <ChangeType> supportedChangeTypes, CalculateTotalChange calculateTotalChange, ApplyTotalChange applyTotalChange) { ChangeDestination = changeDestination; SupportedChangeTypes = supportedChangeTypes ?? new List <ChangeType>(); CalculateTotalChange = calculateTotalChange; ApplyTotalChange = applyTotalChange; }
public static bool TryGetTotalChange(BaseEffectHandler effectHandler, ChangeDestination changeDest, out TotalChange totalChange) { totalChange = null; if (effectHandler.TryGetTotalChange(changeDest, out totalChange)) { return(true); } return(false); }
public void ReapplyTotal(ChangeDestination destination) { TotalChange tc; lock (effectLock) { if (destToTotalChange.TryGetValue(destination, out tc)) { tc.GetApplyFunction()(this, tc); } } }
// register necessary function for ToalChange calculation and application // cd: ChangeDestination to register to protected static bool RegisterDestination(ChangeDestination cd) { DestInitInfo info; List <ChangeDestination> destinations; if (!BaseDestInit.TryGetDestInitInfo(cd, out info)) { MakeLogWarningStatic(typeof(BaseEffectHandler), "Could not register ChangeDestination " + cd + " because there are not entries for it."); return(false); } try { destToCalcTotal.Add(cd, info.CalculateTotalChange); destToApplyTotal.Add(cd, info.ApplyTotalChange); for (int i = 0; i < info.SupportedChangeTypes.Count; i++) { if ((changeTypeToDestinations.TryGetValue(info.SupportedChangeTypes[i], out destinations)) && (!destinations.Contains(cd))) { destinations.Add(ChangeDestination.Effect_Name); } else { changeTypeToDestinations.Add(info.SupportedChangeTypes[i], new List <ChangeDestination>() { cd }); } } } catch (Exception ex) { MakeLogErrorStatic(typeof(BaseEffectHandler), "Failed to register ChangeDestination " + cd + " : " + ex); // clear already reigstered values after unfinished registration // TO DO return(false); } return(true); }
public bool TryGetTotal(ChangeDestination cd, out Change fc) { fc = null; lock (effectLock) { TotalChange tc; if (!TryGetTotalChange(cd, out tc)) { return(false); } fc = tc.GetTotal(); if (fc == null) { return(false); } return(true); } }
private void Awake() { navMeshAgent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); _stateMachine = new StateMachine(); var idle = new Idle(this, navMeshAgent, animator); var walk = new Walk(this, navMeshAgent, animator); var changeDestination = new ChangeDestination(this); var enterDoor = new EnterDoor(this); var interactLever = new InteractWithLever(this, navMeshAgent, animator); At(walk, interactLever, InteractLever()); At(interactLever, idle, () => _currentLever == null); At(walk, enterDoor, EnterDoor()); At(enterDoor, walk, () => true); At(idle, walk, () => _nextDestination != Vector3.zero); At(walk, idle, () => Vector3.Distance(transform.position, _currentDestination) < .1f); At(walk, changeDestination, () => _nextDestination != Vector3.zero); At(changeDestination, walk, () => true); _stateMachine.SetState(idle); void At(IState to, IState from, Func <bool> condition) => _stateMachine.AddTransition(to, from, condition); Func <bool> InteractLever() => () => Vector3.Distance(transform.position, _currentDestination) < .2f && _currentLever != null; Func <bool> EnterDoor() => () => Vector3.Distance(transform.position, _currentDestination) < .15f && _currentDoor != null; }
public static bool TryGetDestInitInfo(ChangeDestination changeDest, out DestInitInfo info) { return(changeDestinationToInfo.TryGetValue(changeDest, out info)); }