AgentPlayer.cs :  » SQL-Clients » Database-Commander » YariSoft » Utils » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » SQL Clients » Database Commander 
Database Commander » YariSoft » Utils » AgentPlayer.cs
using System;
using System.Collections;
using System.Drawing;

namespace YariSoft.Utils{
  [Serializable]
  public struct AgentOperation
  {
    public enum OperationTypeEnum { Animation, Speak, MoveTo };

    public OperationTypeEnum  OperationType;
    public object        Action;

    #region Constructor/Destructor
    public AgentOperation ( OperationTypeEnum OperationType, object Action )
    {
      this.OperationType  = OperationType;
      this.Action      = Action;
    }
    #endregion
  }

  [Serializable]
  public class AgentMovie
  {
    public ArrayList Operations;
    public string   Name;

    #region Constructor/Destructor
    public AgentMovie ( string Name )
    {
      this.Operations = new ArrayList();
      this.Name = Name;
    }
    #endregion

    #region Public functions
    public void AddOperation ( AgentOperation Opeartion )
    {
      this.Operations.Add( Opeartion );
    }
    #endregion
  }

  [Serializable]
  public class AgentPlayer
  {
    public enum MovieTypeEnum { Start, Stop, Error, Question, Busy, DefPosition };

    public Hashtable  Movies = null;
    [NonSerialized()]
    public string FileName    = defaultFileName;
    [NonSerialized()]
    public bool   HasChanges  = false;

    #region Local variables
    [NonSerialized()]
    private  Random generator  = null;
    private const string defaultFileName 
                  = "Untitled.amv";
    #endregion

    #region Constructor/Destructor
    public AgentPlayer ()
    {
      this.Movies = new Hashtable();
      for(int i = (int)MovieTypeEnum.Start; i <= (int)MovieTypeEnum.Busy; i++ ){
        ArrayList agentMovies = new ArrayList ();
        this.Movies.Add ( ( MovieTypeEnum )i, agentMovies );
      }
      this.generator = new Random();
    }
    #endregion

    #region Public functions
    public void AddMovie ( AgentMovie Movie, MovieTypeEnum MovieType )
    {
      ArrayList agentMovies = ( ArrayList )this.Movies[ MovieType ];
      if( agentMovies != null ){
        agentMovies.Add( Movie );
      }
    }

    public void Play ( MovieTypeEnum MovieType, AgentServerObjects.IAgentCharacter Character )
    {
      if( Character == null ){
        return;
      }

      AgentMovie movie = this.GetMovie( MovieType );
      if( movie != null ){
        this.Play( movie, Character );
      }
    }

    public void Play ( AgentMovie Movie, AgentServerObjects.IAgentCharacter Character )
    {
      if( Movie == null ){
        return;
      }

      try{
        int pdwReqID;
        Character.StopAll( 0xFFFFFFF );
        foreach( AgentOperation operation in Movie.Operations ){
          switch( operation.OperationType ){
            case AgentOperation.OperationTypeEnum.Animation:
              Character.Play( ( string )operation.Action, out pdwReqID );
              break;
            case AgentOperation.OperationTypeEnum.Speak:
              Character.Speak( ( string )operation.Action, null, out pdwReqID );
              break;
            case AgentOperation.OperationTypeEnum.MoveTo:
              Point curPoint = ( Point )operation.Action;
              Character.MoveTo( (short)( curPoint.X ), (short)(curPoint.Y), 1, out pdwReqID);
              break;
          }
        }
      }catch{
      }
    }

    public bool SaveToFile()
    {
      bool showDiaolg = false;
      if( this.FileName == defaultFileName ){
        showDiaolg = true;
      }

      if( YariSoft.Utils.ConfigFile.SaveToFile( ref this.FileName, this, showDiaolg ) ){
        this.HasChanges = false;
      }
      return ! this.HasChanges;
    }

    public bool SaveAsToFile()
    {
      if( YariSoft.Utils.ConfigFile.SaveToFile( ref this.FileName, this, true ) ){
        this.HasChanges = false;
      }
      return ! this.HasChanges;
    }

    public static AgentPlayer LoadFromFile( string FileName )
    {
      AgentPlayer result = ( AgentPlayer )YariSoft.Utils.ConfigFile.LoadFromFile( ref FileName, false );
      if( result == null ){
        result = new AgentPlayer();
      } else {
        result.FileName = FileName;
        result.generator = new Random();
      }
      return result;
    }
    #endregion

    #region Private functions
    private AgentMovie GetMovie ( MovieTypeEnum MovieType )
    {
      ArrayList agentMovies = (ArrayList)this.Movies[ MovieType ];
      if( agentMovies == null ){
        return null;
      }

      if( agentMovies.Count == 0 ){
        return null;
      }
      
      return ( AgentMovie )agentMovies[ this.generator.Next( agentMovies.Count ) ];
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.