/// <summary> /// find and apply a specified image from the pony's cache of them. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> private void LoadImage(PonyAction action, PonyDirection direction) { PonyImage image; // find the requested image from the cache. image = this.Image.Find(delegate(PonyImage img){ if (img.Action == action && img.Direction == direction) { return(true); } else { return(false); } }); if (image == null) { Trace.WriteLine(String.Format( "!! no image for {0} {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } ; // and apply it to the pony window. image.ApplyToPonyWindow(this.Window); }
/// <summary> /// is the specified action considered an active action? /// </summary> /// <param name="action"></param> /// <returns></returns> public static bool IsActionActive(PonyAction action) { if (Enum.IsDefined(typeof(PonyActionActive), (int)action)) { return(true); } else { return(false); } }
public static Uri SelectImagePath(string name, PonyAction action, PonyDirection direction) { return new Uri( String.Format( "{0}Resources\\{1}\\{2}{3}.gif", AppDomain.CurrentDomain.BaseDirectory, name, action.ToString(), direction.ToString() ), UriKind.Absolute ); }
/// <summary> /// can the pony do the action requested? /// </summary> /// <param name="action"></param> public bool CanDo(PonyAction action) { // allow anypony to teleport in if they can teleport out. if (action == PonyAction.Teleport2) { return(this.AvailableActions.Contains(PonyAction.Teleport)); } else { return(this.AvailableActions.Contains(action)); } }
public static Uri SelectImagePath(string name, PonyAction action, PonyDirection direction) { return(new Uri( String.Format( "{0}Resources\\{1}\\{2}{3}.gif", AppDomain.CurrentDomain.BaseDirectory, name, action.ToString(), direction.ToString() ), UriKind.Absolute )); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// if she is devoted then she will not allow herself to be distracted /// until this action is done. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> /// <param name="devoted"></param> public void TellWhatDo(PonyAction action, PonyDirection direction, bool devoted) { if (devoted) { // she is devoted to doing this and will stop making decisions // for herself. this.PauseChoiceEngine(); } else { // after she does this she is free to make other choices on // her own. this.ResetChoiceTimer(); } this.TellWhatDo(action, direction); }
/// <summary> /// find and apply a specified image from the pony's cache of them. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> private void LoadImage(PonyAction action, PonyDirection direction) { PonyImage image; // find the requested image from the cache. image = this.Image.Find(delegate(PonyImage img){ if(img.Action == action && img.Direction == direction) return true; else return false; }); if(image == null) { Trace.WriteLine(String.Format( "!! no image for {0} {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; }; // and apply it to the pony window. image.ApplyToPonyWindow(this.Window); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// </summary> /// <param name="action"></param> /// <param name="direction"></param> public void TellWhatDo(PonyAction action, PonyDirection direction) { bool able = true; // if an invalid action was specified, then no. if(direction == PonyDirection.None || action == PonyAction.None) able = false; // if this is an action she is not configured to be able to do then // of course the answer is no. if(!this.CanDo(action)) able = false; if(!able) { Trace.WriteLine(String.Format( "!! {0} cannot {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } Trace.WriteLine(String.Format( ">> {0} will {1} to the {2}", this.Name, action.ToString(), direction.ToString() )); // if this is the first action our pony has done, then we also need to // spool the decision engine up. if(this.ChoiceTimer == null) { this.ChoiceTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Window.Dispatcher); this.ChoiceTimer.Tick += ChooseWhatDo; this.ResetChoiceTimer(); } // no need to muck with the image and window if we are doing more of the // same yeh? also check choicetimer as a means of "is this the first // action ever" to make sure the default gets loaded. if(action != this.Action || direction != this.Direction) { this.Action = action; this.Direction = direction; this.StartAction(); // reset the choice timer to a new interval based on the action // that just happened, but only if it was still enabled. if(this.ChoiceTimer.IsEnabled) this.ResetChoiceTimer(); } // spend the energy associated with this action. if(this.Mode != PonyMode.Clingy) this.EnergySpend(); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// if she is devoted then she will not allow herself to be distracted /// until this action is done. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> /// <param name="devoted"></param> public void TellWhatDo(PonyAction action, PonyDirection direction, bool devoted) { if(devoted) { // she is devoted to doing this and will stop making decisions // for herself. this.PauseChoiceEngine(); } else { // after she does this she is free to make other choices on // her own. this.ResetChoiceTimer(); } this.TellWhatDo(action, direction); }
/// <summary> /// can the pony do the action requested? /// </summary> /// <param name="action"></param> public bool CanDo(PonyAction action) { // allow anypony to teleport in if they can teleport out. if(action == PonyAction.Teleport2) return this.AvailableActions.Contains(PonyAction.Teleport); else return this.AvailableActions.Contains(action); }
/// <summary> /// is the specified action considered an active action? /// </summary> /// <param name="action"></param> /// <returns></returns> public static bool IsActionActive(PonyAction action) { if(Enum.IsDefined(typeof(PonyActionActive), (int)action)) return true; else return false; }
/////////////////////////////////////////////////////////////////////// // instance work ////////////////////////////////////////////////////// public PonyImage(string name, PonyAction action, PonyDirection direction) { this.Action = action; this.Direction = direction; this.Load(PonyImage.SelectImagePath(name,action,direction)); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// </summary> /// <param name="action"></param> /// <param name="direction"></param> public void TellWhatDo(PonyAction action, PonyDirection direction) { bool able = true; // if an invalid action was specified, then no. if (direction == PonyDirection.None || action == PonyAction.None) { able = false; } // if this is an action she is not configured to be able to do then // of course the answer is no. if (!this.CanDo(action)) { able = false; } if (!able) { Trace.WriteLine(String.Format( "!! {0} cannot {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } Trace.WriteLine(String.Format( ">> {0} will {1} to the {2}", this.Name, action.ToString(), direction.ToString() )); // if this is the first action our pony has done, then we also need to // spool the decision engine up. if (this.ChoiceTimer == null) { this.ChoiceTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Window.Dispatcher); this.ChoiceTimer.Tick += ChooseWhatDo; this.ResetChoiceTimer(); } // no need to muck with the image and window if we are doing more of the // same yeh? also check choicetimer as a means of "is this the first // action ever" to make sure the default gets loaded. if (action != this.Action || direction != this.Direction) { this.Action = action; this.Direction = direction; this.StartAction(); // reset the choice timer to a new interval based on the action // that just happened, but only if it was still enabled. if (this.ChoiceTimer.IsEnabled) { this.ResetChoiceTimer(); } } // spend the energy associated with this action. if (this.Mode != PonyMode.Clingy) { this.EnergySpend(); } }
/////////////////////////////////////////////////////////////////////// // instance work ////////////////////////////////////////////////////// public PonyImage(string name, PonyAction action, PonyDirection direction) { this.Action = action; this.Direction = direction; this.Load(PonyImage.SelectImagePath(name, action, direction)); }