Пример #1
0
 public void Awake()
 {
     SpawnMobs();
     dropWeapon    = new EnemyWeaponDrop();
     SW            = new SpawnWeapon();
     wT            = FindObjectOfType <WeaponTable>();
     xpPool        = FindObjectOfType <ExpParticlesPool>();
     expController = FindObjectOfType <ExpController>();
 }
Пример #2
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();
    }
Пример #3
0
 private void Awake()
 {
     if (WeaponTableSingleton == null)
     {
         WeaponTableSingleton = this;
     }
     else if (WeaponTableSingleton != this)
     {
         Destroy(gameObject);
     }
 }
Пример #4
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT = FindObjectOfType <WeaponTable>();

        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();
        for (int i = 0; i < dropList.Count; i++)
        {
            DicToUseInDrop.Add(dropList[i].iD, dropChanceList[i]);
        }
    }
Пример #5
0
 public void Stop()
 {
     //EventCommunicator.SendSimStopEvent();
     //handshakeManagerThread.Abort();
     if (coordinatorThread != null)
     {
         coordinatorThread.Abort();
     }
     if (eCommReceiver != null)
     {
         eCommReceiver.Abort();
     }
     //textChatServerThread.Abort();
     HappeningList.Happenings.Clear();
     TimerQueueClass.Clear();
     IncomingList.Clear();
     Genealogy.Clear();
     StatesForUnits.Clear();
     UnitFacts.CurrentUnitStates.Clear();
     UnitFacts.ClearDMTables();
     UnitFacts.Data.Clear();
     ChatRooms.DropAllRooms();
     VoiceChannels.DropAllChannels();
     WhiteboardRooms.DropAllRooms();
     TimerControl((int)TimerControls.Reset);
     //        ScenarioToQueues.Reset();
     WeaponTable.Clear();
     NetworkTable.Clear();
     SubplatformRecords.Clear();
     Engrams.Clear();
     Scores.Clear();
     DebugLogger.StopLogging();
     NameLists.Clear();
     DecisionMakerType.ClearDMTable();
     SpeciesType.ClearSpeciesTable();
     Metronome.GetInstance().CleanupMetronome();
 }
Пример #6
0
        /// <summary>
        /// Creates the class (one instance only) that parses a scenario and puts events on queues
        /// </summary>
        /// <param name="scenarioFile"></param>
        public ScenarioToQueues(string scenarioFile, string schemaFile)
        {
            TimerQueueClass timerQueue = new TimerQueueClass();
            // Extract fields from the XML file (and schema)
            // see http://weblogs.asp.net/dbrowning/articles/114561.aspx
            // paths to xml/xsd
            // const string path = @"C:\Documents and Settings\dgeller\My Documents\Visual Studio 2005\Projects\";
            //const string scenarioFile = path + @"DDD\Scenario.xml";
            // const string xsdPath = path + @"XMLTrial\XMLTrial\ScenarioSchema.xsd";



            FileStream fs;
            Boolean    returnVal;

//            ScenarioToQueues.schemaFile = schemaFile;

            //    try
            //  {
            returnVal = ValidateScenario(scenarioFile);
            // }

            /*    catch (System.Exception e)
             *  {
             *
             *      string message = "Failed to validate schema. " + e.Message;
             *      Coordinator.debugLogger.LogException("Scenario Reader", message);
             *      throw new ApplicationException(message, e);
             *  }*/

            if (!returnVal)
            {
                return;
            }


            try
            {
                fs = File.Open(scenarioFile, FileMode.Open);
            }
            catch (System.Exception e)
            {
                string message = "Could not open scenario file on pass 2." + e.Message;
                Coordinator.debugLogger.LogException("Scenario Reader", message);
                throw new ApplicationException(message, e);
            }

            /// XmlReader readerTwo;
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(null, ScenarioToQueues.namedSchemaFile);//+".xsd");
                XmlReaderSettings readerSettings = new XmlReaderSettings();

                // readerSettings.ValidationType = ValidationType.Schema;
                readerSettings.IgnoreWhitespace = true;
                // makes no difference ?!               readerSettings.IgnoreWhitespace = true;
                //   readerSettings.ValidationEventHandler += new ValidationEventHandler(SchemaValidationHandler);

                reader = XmlReader.Create(fs, readerSettings);
                parser.SetReader(reader);
            }
            catch (System.Exception e)
            {
                fs.Close();
                string message = "Could not open schema file. " + e.Message;
                Coordinator.debugLogger.LogException("Scenario Reader", message);
                throw new ApplicationException(message, e);
            }

            //Build reverse dictionary of commnds->stage
            //This lets us enforce moving through the commands in a prescribed order
            Dictionary <string, int> stages = new Dictionary <string, int>();

            string[][] stageMembers = parser.StageMembers();
            for (int level = 0; level < stageMembers.Length; level++)
            {
                for (int member = 0; member < stageMembers[level].Length; member++)
                {
                    stages[stageMembers[level][member]] = level;
                }
            }
            int    currentStage = 0;
            string scenarioName = "";
            string description  = "";


            reader.Read(); // opens, gets to xml declaration
            reader.Read();
            try
            {
                if ("Scenario" == reader.Name) // only Scenario can be top level
                {
                    reader.Read();             // pass by "Scenario"

                    while (!reader.EOF && !((XmlNodeType.EndElement == reader.NodeType) && ("Scenario" == reader.Name)))
                    {
                        //Coordinator.debugLogger.Writeline(".");

                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "ELEMENT " + reader.Name, "test");
                            if (stages.ContainsKey(reader.Name))
                            {
                                if (stages[reader.Name] < currentStage)
                                {
                                    throw new ApplicationException("Command " + reader.Name + " out of sequence.");
                                }
                                currentStage = stages[reader.Name];
                                //NB, if command is not found in stages it will be trapped in the switch's default
                            }
                            switch (reader.Name)
                            {
                            case "ScenarioName":
                                scenarioName = parser.pGetString();
                                break;

                            case "Description":
                                description = parser.pGetString();
                                break;

                            case "ClientSideAssetTransfer":
                                ClientSideAssetTransferType assetTransfers = new ClientSideAssetTransferType(parser.pGetBoolean());
                                TimerQueueClass.SendBeforeStartup(assetTransfers);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ClientSideAssetTransferType ", "test");
                                break;

                            case "ClientSideStartingLabelVisible":
                                ClientSideStartingLabelVisibleType labelsVisible = new ClientSideStartingLabelVisibleType(parser.pGetBoolean());
                                TimerQueueClass.SendBeforeStartup(labelsVisible);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ClientSideStartingLabelVisibleType ", "test");
                                break;

                            case "ClientSideRangeRingVisibility":
                                ClientSideRangeRingVisibilityType rangeRingVisibility = new ClientSideRangeRingVisibilityType(parser.pGetString());
                                TimerQueueClass.SendBeforeStartup(rangeRingVisibility);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "ClientSideRangeRingVisibilityType", "test");
                                break;

                            case "Playfield":
                                // except for the optional name/description
                                // Playfield must be first scenario item sent
                                // enforced by schema
                                string             errorText   = string.Empty;
                                string             imgLibPath  = string.Empty;
                                string             mapFilePath = string.Empty;
                                string             hostname    = Aptima.Asim.DDD.CommonComponents.ServerOptionsTools.ServerOptions.HostName;
                                pPlayfieldType     pDefine     = parser.pGetPlayfield();
                                PlayfieldEventType playfield   = new PlayfieldEventType(pDefine);
                                playfield.ScenarioName = scenarioName;
                                playfield.Description  = description;
                                if (playfield.IconLibrary.EndsWith(".dll"))
                                {
                                    imgLibPath = String.Format(@"\\{0}\{1}", ServerOptions.DDDClientPath, playfield.IconLibrary);         //icon library does include dll extension
                                }
                                else
                                {
                                    imgLibPath = String.Format(@"\\{0}\{1}.dll", ServerOptions.DDDClientPath, playfield.IconLibrary);         //icon library doesnt include dll extension
                                }
                                mapFilePath = String.Format(@"\\{0}\MapLib\{1}", ServerOptions.DDDClientPath, playfield.MapFileName);         //map file includes file extension

                                //check image library path
                                if (!File.Exists(imgLibPath))
                                {
                                    if (System.Windows.Forms.MessageBox.Show(String.Format("The server was not able to locate the image library in {0}.  There is a chance that clients connecting to this machine will have a similar issue locating this file.  If you'd still like to run the simulation, click Yes.  If you'd like to stop the server, click No.", imgLibPath), "File not found", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                                    {        //User wants to continue
                                    }
                                    else
                                    {         //user wants to stop server
                                        throw new Exception("User Cancelled server process.  Server was unable to locate the image library at " + imgLibPath);
                                        return;
                                    }
                                }

                                //check map file path
                                if (!File.Exists(mapFilePath))
                                {
                                    if (System.Windows.Forms.MessageBox.Show(String.Format("The server was not able to locate the map file in {0}.  There is a chance that clients connecting to this machine will have a similar issue locating this file.  If you'd still like to run the simulation, click Yes.  If you'd like to stop the server, click No.", mapFilePath), "File not found", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                                    {        //User wants to continue
                                    }
                                    else
                                    {         //user wants to stop server
                                        throw new Exception("User Cancelled server process.  Server was unable to locate the map file at " + mapFilePath);
                                        return;
                                    }
                                }
                                TimerQueueClass.SendBeforeStartup(playfield);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Playfield", "test");

                                TimerQueueClass.SendBeforeStartup(new RandomSeedType());
                                break;

                            case "LandRegion":
                                pLandRegionType region      = parser.pGetLandRegion();
                                RegionEventType regionEvent = new RegionEventType(region);

                                TimerQueueClass.SendBeforeStartup(regionEvent);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " LandRegion " + regionEvent.UnitID, "test");

                                break;

                            /*
                             * case "ScoringRegion":
                             * pScoringRegionType regionS = parser.pGetScoringRegion();
                             * RegionEventType regionEventS = new RegionEventType(regionS);
                             * TimerQueueClass.SendBeforeStartup(regionEventS);
                             * Coordinator.debugLogger.Writeline("ScenarioToQueues", " ScoringRegion " + regionEventS.UnitID, "test");
                             * break;
                             */
                            case "ActiveRegion":
                                pActiveRegionType regionA      = parser.pGetActiveRegion();
                                RegionEventType   regionEventA = new RegionEventType(regionA);
                                if (!NameLists.activeRegionNames.New(regionA.ID, regionEventA))
                                {
                                    throw new ApplicationException("Duplicate active region name " + regionA.ID);
                                }
                                TimerQueueClass.SendBeforeStartup(regionEventA);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ActiveRegion " + regionEventA.UnitID, "test");
                                break;

                            case "Team":
                                pTeamType team      = parser.pGetTeam();
                                TeamType  teamEvent = new TeamType(team);
                                for (int i = 0; i < teamEvent.Count(); i++)
                                {
                                    UnitFacts.AddEnemy(teamEvent.Name, teamEvent.GetEnemy(i));
                                }
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Team " + team.Name.ToString(), "test");
                                if (!NameLists.teamNames.New(team.Name, teamEvent))
                                {
                                    throw new ApplicationException("Duplicate team name " + team.Name);
                                }

                                TimerQueueClass.SendBeforeStartup(teamEvent);
                                break;

                            case "DecisionMaker":
                                DecisionMakerType decisionMaker = new DecisionMakerType(parser.pGetDecisionMaker());
                                UnitFacts.AddDM(decisionMaker.Identifier, decisionMaker.Chroma, decisionMaker.Team);
                                TimerQueueClass.SendBeforeStartup(decisionMaker);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Decision Maker ", "test");
                                break;

                            case "Network":
                                NetworkType network = new NetworkType(parser.pGetNetwork());
                                NetworkTable.AddNetwork(network);
                                TimerQueueClass.SendBeforeStartup(network);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Network ", "test");
                                break;


                            case "Sensor":
                                //sensor follows Playfield
                                pSensor sen = parser.pGetSensor();
                                // if Attribute is "all" there will be one cone; only extent is filled in from parser
                                if (sen.Attribute == "All")
                                {
                                    sen.Cones[0].Spread = 360;
                                    sen.Cones[0].Level  = "Total";
                                }
                                SensorTable.Add(sen.Name, new SensorType(sen.Attribute, sen.IsEngram, sen.TypeIfEngram, sen.Cones));

                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Sensor " + sen.Name.ToString(), "test");

                                break;

                            /*    case "TimeToRemove":
                             *          Defaults.DefaultTimeToRemove = parser.pGetInt();
                             *          break;
                             */
                            case "Classifications":
                                ClassificationsType classifications = new ClassificationsType(parser.pGetClassifications());
                                TimerQueueClass.SendBeforeStartup(classifications);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Classifications ", "test");
                                break;

                            case "TimeToAttack":
                                Defaults.DefaultTimeToAttack = parser.pGetInt() * 1000;
                                break;

                            case "Genus":
                                pGenusType g = parser.pGetGenus();
                                if (!NameLists.speciesNames.New(g.Name, g))
                                {
                                    throw new ApplicationException("Duplicate use of genus name " + g.Name);
                                }

                                Genealogy.Add(g.Name);


                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Genus " + g.Name, "test");
                                // StartupForUnits.Add(genus);
                                break;

                            case "Species":
                                // Genus and species come after playfield


                                pSpeciesType s       = parser.pGetSpecies();
                                SpeciesType  species = new SpeciesType(s);
                                if (!NameLists.speciesNames.New(species.Name, species))
                                {
                                    throw new ApplicationException("Duplicate use of species name " + species.Name);
                                }
                                Genealogy.Add(species.Name, species.BasedOn);
                                if (species.IsWeapon)
                                {
                                    WeaponTable.Add(species.Name);
                                }

                                WorkStates.Clear();
                                WorkStates.Add(species.States);
                                StatesForUnits.AddStatesOf(species.Name, WorkStates.CollapseStates(species.Name, species.BasedOn));
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Species " + s.Name, "test");
                                // StartupForUnits.Add(species);
                                break;

                            case "Create_Event":
                                //string newId;
                                //   Create_EventType platformCreate;//used for sub platforms
                                pCreateType      c           = parser.pGetCreate();
                                Create_EventType createEvent = new Create_EventType(c);
                                Genealogy.Add(createEvent.UnitID, createEvent.UnitBase);
                                createEvent.Genus = Genealogy.GetGenus(createEvent.UnitID);
                                UnitFacts.AddUnit(createEvent.UnitID, createEvent.Owner, createEvent.UnitBase);
                                createEvent.Parameters = new ObjectDictionary();

                                SpeciesType speciesInfo = (SpeciesType)NameLists.speciesNames[createEvent.UnitBase];

                                foreach (KeyValuePair <string, StateBody> kvp in StatesForUnits.StateTable[createEvent.UnitBase])
                                {
                                    string            stateName = kvp.Key;
                                    ExtendedStateBody extended  = new ExtendedStateBody(kvp.Value);

                                    //end species dependent atts
                                    createEvent.Parameters.Add(stateName, (object)extended);
                                    //               EngramDependants.Add(createEvent.UnitID, extended);
                                }



                                //       TimerQueueClass.Add(1, createEvent);
                                NameLists.unitNames.New(createEvent.UnitID, null);
                                TimerQueueClass.SecondarySendBeforeStartup(createEvent);
                                UnitFacts.CurrentUnitStates.Add(createEvent.UnitID, "");
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "createEvent for " + createEvent.UnitID, "test");

                                //for some reason this docs everyone at time 1.  this seems to be the heart of the bug

                                /*
                                 * for (int i = 0; i < createEvent.Subplatforms.Count;i++ )
                                 * {
                                 * SubplatformDockType dockNotice = new SubplatformDockType(createEvent.Subplatforms[i], createEvent.UnitID);
                                 * dockNotice.Time = 1;
                                 * TimerQueueClass.SecondarySendBeforeStartup(dockNotice);
                                 *
                                 * }
                                 */
                                break;

                            case "Reveal_Event":
                                pRevealType      r           = parser.pGetReveal();
                                Reveal_EventType revealEvent = new Reveal_EventType(r);
                                revealEvent.Genus = Genealogy.GetGenus(revealEvent.UnitID);
                                if (r.Time > 1)
                                {
                                    TimerQueueClass.Add(r.Time, revealEvent);
                                }
                                else
                                {
                                    TimerQueueClass.SecondarySendBeforeStartup(revealEvent);
                                }
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "revealEvent for  " + revealEvent.UnitID + " at time" + r.Time.ToString(), "test");
                                RevealDocked(r.UnitID, r.Time);
                                break;

                            case "Move_Event":
                                pMoveType m = parser.pGetMove();
                                if (!UnitFacts.IsAUnit(m.UnitID))
                                {
                                    throw new ApplicationException("Cannot move non-exsitant unit " + m.UnitID);
                                }
                                Move_EventType moveEvent = new Move_EventType(m);
                                TimerQueueClass.Add(moveEvent.Time, moveEvent);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " moveEvent for  " + moveEvent.UnitID, "test");
                                break;

                            case "Completion_Event":
                                HappeningCompletionType completionType = new HappeningCompletionType(parser.pGetHappeningCompletion());
                                HappeningList.Add(completionType);
                                break;

                            case "Species_Completion_Event":
                                pSpeciesCompletionType sct = parser.pGetSpeciesCompletion();
                                SpeciesCompletionType  speciesCompletion = new SpeciesCompletionType(sct);
                                SpeciesHappeningList.Add(speciesCompletion);
                                break;

                            case "Reiterate":
                                ReiterateType  reiterate = new ReiterateType(parser.pGetReiterate());
                                Move_EventType mQueued   = (Move_EventType)(reiterate.ReiterateList[0]);
                                Move_EventType mQCopy    = (Move_EventType)(reiterate.ReiterateList[0]);
                                mQueued.Range = reiterate.Range;
                                mQueued.Time  = reiterate.Time;
                                TimerQueueClass.Add(mQueued.Time, mQueued);

                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " moveEvent from reiterate for  " + mQueued.UnitID, "test");
                                reiterate.ReiterateList.RemoveAt(0);
                                reiterate.ReiterateList.Add(mQCopy);
                                HappeningCompletionType envelope = new HappeningCompletionType(reiterate);
                                HappeningList.Add(envelope);
                                break;

                            case "StateChange_Event":
                                StateChangeEvent change = new StateChangeEvent(parser.pGetStateChange());
                                if (!UnitFacts.IsAUnit(change.UnitID))
                                {
                                    throw new ApplicationException("State change event references unknown unit " + change.UnitID);
                                }
                                if (!StatesForUnits.UnitHasState(change.UnitID, change.NewState))
                                {
                                    throw new ApplicationException("State chage for " + change.UnitID + " refers to unknwon state " + change.NewState);
                                }
                                for (int i = 0; i < change.Except.Count; i++)
                                {
                                    //                    if (!StatesForUnits.UnitHasState(Genealogy.GetBase(change.UnitID), change.Except[i])) throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.Except);
                                    if (!StatesForUnits.UnitHasState(change.UnitID, change.Except[i]))
                                    {
                                        throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.Except);
                                    }
                                }
                                for (int i = 0; i < change.From.Count; i++)
                                {
                                    //                if (!StatesForUnits.UnitHasState(Genealogy.GetBase(change.UnitID), change.From[i])) throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.From);
                                    if (!StatesForUnits.UnitHasState(change.UnitID, change.From[i]))
                                    {
                                        throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.From);
                                    }
                                }
                                TimerQueueClass.Add(change.Time, change);
                                break;

                            case "Transfer_Event":
                                TransferEvent t = new TransferEvent(parser.pGetTransfer());

                                if (!UnitFacts.IsDM(t.From))
                                {
                                    throw new ApplicationException("Transfer event references unknown DM (from) " + t.From);
                                }
                                if (!UnitFacts.IsDM(t.To))
                                {
                                    throw new ApplicationException("Transfer event references unknown DM (to) " + t.To);
                                }
                                if (!UnitFacts.IsAUnit(t.UnitID))
                                {
                                    throw new ApplicationException("Transfer event references unknown unit " + t.UnitID);
                                }
                                TimerQueueClass.Add(t.Time, t);
                                break;

                            case "Launch_Event":
                                LaunchEventType launch = new LaunchEventType(parser.pGetLaunch());
                                if (!UnitFacts.IsAUnit(launch.UnitID))
                                {
                                    throw new ApplicationException("Cannot launch from non-existent unit " + launch.UnitID);
                                }
                                TimerQueueClass.Add(launch.Time, launch);


                                break;

                            case "WeaponLaunch_Event":

                                WeaponLaunchEventType weaponLaunch = new WeaponLaunchEventType(parser.pGetWeaponLaunch());
                                if (!UnitFacts.IsAUnit(weaponLaunch.UnitID))
                                {
                                    throw new ApplicationException("Cannot launch from non-existent unit " + weaponLaunch.UnitID);
                                }
                                TimerQueueClass.Add(weaponLaunch.Time, weaponLaunch);


                                break;

                            case "DefineEngram":
                                pDefineEngramType defineEngram = parser.pGetDefineEngram();
                                Engrams.Create(defineEngram.Name, defineEngram.EngramValue, defineEngram.Type);
                                TimerQueueClass.SendBeforeStartup(new EngramSettingType(defineEngram.Name, "", defineEngram.EngramValue, defineEngram.Type));
                                break;

                            case "ChangeEngram":
                                ChangeEngramType changeEngram = new ChangeEngramType(parser.pGetChangeEngram());
                                if (!Engrams.ValidUpdate(changeEngram.Name, changeEngram.EngramValue))
                                {
                                    throw new ApplicationException("Illegal value " + changeEngram.EngramValue + " for engram " + changeEngram.Name);
                                }
                                TimerQueueClass.Add(changeEngram.Time, changeEngram);
                                //  Engrams.SendUpdate(changeEngram.Name);
                                break;

                            case "RemoveEngram":
                                RemoveEngramEvent removeEngram = new RemoveEngramEvent(parser.pGetRemoveEngram());
                                TimerQueueClass.Add(removeEngram.Time, removeEngram);
                                break;

                            //These chat commands are those from the scenario only;
                            // thos from client are handled immediately
                            case "OpenChatRoom":
                                OpenChatRoomType openChatRoom = new OpenChatRoomType(parser.pGetOpenChatRoom());
                                TimerQueueClass.Add(openChatRoom.Time, openChatRoom);
                                break;

                            case "CloseChatRoom":
                                CloseChatRoomType closeChatRoom = new CloseChatRoomType(parser.pGetCloseChatRoom());

                                TimerQueueClass.Add(closeChatRoom.Time, closeChatRoom);
                                break;

                            /* Not implemented yet
                             * case "DropChatters":
                             *     DropChattersType dropChatters = new DropChattersType(parser.pGetDropChatters());
                             *     TimerQueueClass.Add(dropChatters.Time, dropChatters);
                             *     break;
                             * case "AddChatters":
                             *     AddChattersType addChatters = new AddChattersType(parser.pGetAddChatters());
                             *     TimerQueueClass.Add(addChatters.Time, addChatters);
                             *     break;
                             *
                             */
                            case "OpenWhiteboardRoom":
                                OpenWhiteboardRoomType openWhiteboardRoom = new OpenWhiteboardRoomType(parser.pGetOpenWhiteboardRoom());
                                TimerQueueClass.Add(openWhiteboardRoom.Time, openWhiteboardRoom);
                                break;

                            case "OpenVoiceChannel":
                                OpenVoiceChannelType openVoiceChannel = new OpenVoiceChannelType(parser.pGetOpenVoiceChannel());
                                TimerQueueClass.Add(openVoiceChannel.Time, openVoiceChannel);
                                break;

                            case "CloseVoiceChannel":
                                CloseVoiceChannelType closeVoiceChannel = new CloseVoiceChannelType(parser.pGetCloseVoiceChannel());
                                TimerQueueClass.Add(closeVoiceChannel.Time, closeVoiceChannel);
                                break;

                            /*
                             * //Removed before 4.1
                             * case "GrantVoiceChannelAccess":
                             * GrantVoiceAccessType grantVoiceChannelAccess = new GrantVoiceAccessType(parser.pGetGrantVoiceChannelAccess());
                             * TimerQueueClass.Add(grantVoiceChannelAccess.Time, grantVoiceChannelAccess);
                             * break;
                             * case "RemoveVoiceChannelAccess":
                             * RemoveVoiceAccessType removeVoiceChannelAccess = new RemoveVoiceAccessType(parser.pGetRemoveVoiceChannelAccess());
                             * TimerQueueClass.Add(removeVoiceChannelAccess.Time, removeVoiceChannelAccess);
                             * break;
                             */
                            case "Rule":
                                pScoringRuleType srt       = parser.pGetScoringRule();
                                ScoringRuleType  scoreRule = new ScoringRuleType(srt);
                                if (!NameLists.ruleNames.New(srt.Name, scoreRule))
                                {
                                    throw new ApplicationException("Duplicate scoring rule name " + srt.Name);
                                }
                                ScoringRules.Add(scoreRule);
                                break;

                            case "Score":
                                pScoreType pst = parser.pGetScore();
                                ScoreType  st  = new ScoreType(pst);
                                if (!NameLists.scoreNames.New(pst.Name, st))
                                {
                                    throw new ApplicationException("Duplicate score name " + pst.Name);
                                }
                                Scores.Register(st);
                                break;

                            case "FlushEvents":
                                FlushEvents flush = new FlushEvents(parser.pGetFlushEventsType());
                                TimerQueueClass.Add(flush.Time, flush);
                                break;

                            case "SendChatMessage":
                                SendChatMessageType sendChat = new SendChatMessageType(parser.pGetSendChatMessage());
                                if (!UnitFacts.IsDM(sendChat.Sender) && !("EXP" == sendChat.Sender))
                                {
                                    throw new ApplicationException("In SendChatMessage, '" + sendChat.Sender + "' is not a valid DM name.");
                                }
                                // Note: Can't validate chat room name at parse time; it might not have been created yet
                                TimerQueueClass.Add(sendChat.Time, sendChat);
                                break;

                            case "Apply":
                                ApplyType apply = new ApplyType(parser.pGetApply());
                                //what does this do?
                                TimerQueueClass.Add(apply.Time, apply);
                                break;

                            case "SendVoiceMessage":
                                SendVoiceMessageType playVoiceMessage = new SendVoiceMessageType(parser.pGetSendVoiceMessage());
                                //what does this do?
                                TimerQueueClass.Add(playVoiceMessage.Time, playVoiceMessage);
                                break;

                            case "SendVoiceMessageToUser":
                                SendVoiceMessageToUserType playVoiceMessageToUser = new SendVoiceMessageToUserType(parser.pGetSendVoiceMessageToUser());
                                //what does this do?
                                TimerQueueClass.Add(playVoiceMessageToUser.Time, playVoiceMessageToUser);
                                break;

                            default:
                                throw new ApplicationException("ScenarioToQueues: Unknown Scenario Element is *" + reader.Name);
                            }    //switch
                            break;

                        default:
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "Unhandled or out-of-sequence XML tag " + reader.Value, "test");
                            reader.Read();
                            break;
                        } //switch
                    }     //while
                      // All of scenario processed. Now do last things

                    //verify that the Chat, Whiteboard, and Voice lists contain only DMs and make them symmetric.
                    List <string> allDMs = UnitFacts.GetAllDms();
                    for (int i = 0; i < allDMs.Count; i++)
                    {
                        DecisionMakerType thisDM = DecisionMakerType.GetDM(allDMs[i]);

                        for (int j = 0; j < thisDM.ChatPartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.ChatPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.ChatPartners[j] + "' found as chat partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.ChatPartners[j]);
                            if (!partnerDM.ChatPartners.Contains(allDMs[i]))
                            {
                                partnerDM.MayChatWith(allDMs[i]);
                            }
                        }

                        for (int j = 0; j < thisDM.WhiteboardPartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.WhiteboardPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.WhiteboardPartners[j] + "' found as whiteboard partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.WhiteboardPartners[j]);
                            if (!partnerDM.WhiteboardPartners.Contains(allDMs[i]))
                            {
                                partnerDM.MayWhiteboardWith(allDMs[i]);
                            }
                        }

                        for (int j = 0; j < thisDM.VoicePartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.ChatPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.VoicePartners[j] + "' found as voice partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.VoicePartners[j]);
                            if (!partnerDM.VoicePartners.Contains(allDMs[i]))
                            {
                                partnerDM.MaySpeakWith(allDMs[i]);
                            }
                        }
                    }

                    // Add networks for DMs that have none
                    List <string> dmList = UnitFacts.GetAllDms();
                    for (int nextDM = 0; nextDM < dmList.Count; nextDM++)
                    {
                        if (!NetworkTable.IsNetworkMember(dmList[nextDM]))
                        {
                            string netName = "Network-For-" + dmList[nextDM];
                            NetworkTable.AddMember(netName, dmList[nextDM]);
                            NetworkType newNet = new NetworkType(netName);
                            newNet.Add(dmList[nextDM]);
                            TimerQueueClass.SendBeforeStartup(newNet);
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "Network ", "test");
                        }
                    }
                    //AD: Don't create default chat room, user should have control of this
                    // Create the detault Broadcast chatroom
                    //OpenChatRoomType broadcastChatRoom = new OpenChatRoomType(1, "", "Broadcast", dmList);
                    //TimerQueueClass.SendBeforeStartup(broadcastChatRoom);
                }//if
            }
            catch (System.Exception e)
            {
                if (e.Message.StartsWith("User Cancelled"))
                {//This means a missing map or icon library, and the user wanted to stop the server.  Do not write to error log, just stop the server.
                    throw e;
                }
                string message = "Failure in Parsing Control for next tag=" + reader.Name + " : " + e.Message;
                Coordinator.debugLogger.LogException("ScenarioReader", message);
                throw new ApplicationException(message, e);
            }
            finally
            {
                reader.Close();
                fs.Close();
                // Coordinator.debugLogger.Writeline("ScenarioToQueues", "Done", "general");
            }
        }//
Пример #7
0
 private void Start()
 {
     dropWeapon = new EnemyWeaponDrop();
     SW         = new SpawnWeapon();
     wT         = FindObjectOfType <WeaponTable>();
 }
Пример #8
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        var idle    = new State <OnCondition>("Idle");
        var persuit = new State <OnCondition>("Persuit");
        var attack  = new State <OnCondition>("Attack");
        var skill   = new State <OnCondition>("Skill");
        var die     = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSkill >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSkill += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSkill     += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSkill  += Time.deltaTime;
            timeToAttack += Time.deltaTime;
            if (timeToSkill >= cooldownSequence)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            else
            {
                if (timeToAttack >= 0.5f)
                {
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1.5f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };

        skill.OnEnter += () =>
        {
            cooldownSequence *= 1.5f;
            timeToSkill       = 0;
            Clone();
            fsm.Feed(OnCondition.Idle);
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        //////////////////

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.SkillReady, skill);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Idle, idle);
        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.SkillReady, skill);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.Persuit, persuit);
        attack.AddTransition(OnCondition.SkillReady, skill);
        attack.AddTransition(OnCondition.Die, die);

        skill.AddTransition(OnCondition.Idle, idle);
        skill.AddTransition(OnCondition.Die, die);

        ///////////////

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #9
0
    void Start()
    {
        SW = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT = weaponTable.GetComponent <WeaponTable>();

        _special2 = true;
        howManySpacesBetwennSkulls = 3;
        howManyShoots            = 3;
        timerBetweenShoots       = 0.8f;
        howManyShootsInTheCircle = 8;
        timerToAnySpecial        = 1;
        timerSpecial2            = 10;

        var idle        = new State <OnCondition>("Idle");
        var die         = new State <OnCondition>("Die");
        var scream      = new State <OnCondition>("Scream");
        var special1    = new State <OnCondition>("Special1");
        var special2    = new State <OnCondition>("Special2");
        var special3    = new State <OnCondition>("Special3");
        var attack      = new State <OnCondition>("Attack");
        var persuit     = new State <OnCondition>("Persuit");
        var changePhase = new State <OnCondition>("ChangePhase");
        var show        = new State <OnCondition>("Show");


        show.AddTransition(OnCondition.Idle, idle);

        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Scream, scream);
        idle.AddTransition(OnCondition.ChangePhase, changePhase);
        idle.AddTransition(OnCondition.Die, die);
        idle.AddTransition(OnCondition.Show, show);

        scream.AddTransition(OnCondition.Special1, special1);
        scream.AddTransition(OnCondition.Special2, special2);
        scream.AddTransition(OnCondition.Special3, special3);
        scream.AddTransition(OnCondition.Idle, idle);
        scream.AddTransition(OnCondition.Die, die);

        changePhase.AddTransition(OnCondition.Idle, idle);

        special1.AddTransition(OnCondition.Idle, idle);
        special1.AddTransition(OnCondition.Die, die);
        special1.AddTransition(OnCondition.ChangePhase, changePhase);

        special2.AddTransition(OnCondition.Idle, idle);
        special2.AddTransition(OnCondition.Die, die);
        special2.AddTransition(OnCondition.ChangePhase, changePhase);

        special3.AddTransition(OnCondition.Idle, idle);
        special3.AddTransition(OnCondition.Die, die);
        special3.AddTransition(OnCondition.ChangePhase, changePhase);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.Die, die);
        attack.AddTransition(OnCondition.ChangePhase, changePhase);

        persuit.AddTransition(OnCondition.Idle, idle);
        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.Scream, scream);
        persuit.AddTransition(OnCondition.Die, die);
        persuit.AddTransition(OnCondition.ChangePhase, changePhase);

        idle.OnEnter += () =>
        {
            anim.Play("Idle");
        };

        idle.OnUpdate += () =>
        {
            if ((Vector3.Distance(target.transform.position, transform.position) < radiusToPersuit) && timerToAnySpecial <= 0 && (timerSpecial1 <= 0 || timerSpecial2 <= 0 || timerSpecial3 <= 0))
            {
                fsm.Feed(OnCondition.Scream);
            }
            else if (Vector3.Distance(target.transform.position, transform.position) < radiusToPersuit)
            {
                fsm.Feed(OnCondition.Persuit);
            }
            if (Vector3.Distance(target.transform.position, transform.position) < radiusToDetect && !isAttacking)
            {
                transform.LookAt(target);
            }
        };
        show.OnEnter += () =>
        {
            anim.Play("Explode");
        };
        changePhase.OnEnter += () =>
        {
            anim.Play("Explode");
            Explosion();
            StartCoroutine(TimerToIdle(1));
        };
        scream.OnEnter += () =>
        {
            anim.Play("Skill");
        };
        scream.OnUpdate += () =>
        {
            if (CanUseSpecial)
            {
                if (timerSpecial1 <= 0 && _special1)
                {
                    fsm.Feed(OnCondition.Special1);
                    _special1 = false;
                    _special3 = true;
                }
                else if (timerSpecial2 <= 0 && _special2)
                {
                    fsm.Feed(OnCondition.Special2);
                    _special2 = false;
                    _special1 = true;
                }
                else if (timerSpecial3 <= 0 && _special3)
                {
                    fsm.Feed(OnCondition.Special3);
                    _special3 = false;
                    _special2 = true;
                }
            }
        };
        scream.OnExit += () =>
        {
            timerToAnySpecial = 8;
        };

        special1.OnEnter += () =>
        {
            Special1();
            StartCoroutine(TimerToIdle(1));
        };

        special1.OnExit += () =>
        {
            timerSpecial1 = 21;
            CanUseSpecial = false;
        };

        special2.OnEnter += () =>
        {
            Special2();
            StartCoroutine(TimerToIdle(2));
        };
        special2.OnUpdate += () =>
        {
            if (Vector3.Distance(target.transform.position, transform.position) < radiusToDetect)
            {
                transform.LookAt(target);
            }
        };
        special2.OnExit += () =>
        {
            CanUseSpecial = false;
            timerSpecial2 = 19;
        };

        special3.OnEnter += () =>
        {
            Special3();
            StartCoroutine(TimerToIdle(1));
        };

        special3.OnExit += () =>
        {
            CanUseSpecial = false;
            timerSpecial3 = 20;
        };

        attack.OnEnter += () =>
        {
            anim.Play("Attack");
            isAttacking = true;
        };

        attack.OnUpdate += () =>
        {
            if (timerToAttack > 0)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        attack.OnExit += () =>
        {
            isAttacking = false;
        };

        persuit.OnEnter += () =>
        {
            anim.Play("Run");
        };
        persuit.OnUpdate += () =>
        {
            if (Vector3.Distance(target.transform.position, transform.position) < radiusToPersuit && timerToAnySpecial <= 0 && (timerSpecial1 <= 0 || timerSpecial2 <= 0 || timerSpecial3 <= 0))
            {
                fsm.Feed(OnCondition.Scream);
            }
            else if (Vector3.Distance(target.transform.position, transform.position) > radiusToPersuit)
            {
                fsm.Feed(OnCondition.Idle);
            }
            else if (Vector3.Distance(target.transform.position, transform.position) < radiusToAttack && timerToAttack <= 0)
            {
                fsm.Feed(OnCondition.Attack);
            }
            Vector3 dirToGo = new Vector3(target.transform.position.x - transform.position.x, 0, target.transform.position.z - transform.position.z);
            transform.forward   = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
            transform.position += transform.forward * speed * Time.deltaTime;
        };
        die.OnEnter += () =>
        {
            anim.Play("Death");
            GetWeapon();
        };

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #10
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        bossSword = GetComponentInChildren <BossSword>();
        var idle          = new State <OnCondition>("Idle");
        var persuit       = new State <OnCondition>("Persuit");
        var attack        = new State <OnCondition>("Attack");
        var skill         = new State <OnCondition>("Skill");
        var teletransport = new State <OnCondition>("Teletransport");
        var summon        = new State <OnCondition>("Summon");
        var heal          = new State <OnCondition>("Heal");
        var die           = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSequence >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.TP);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSequence += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSequence  += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSequence += Time.deltaTime;
            timeToAttack   += Time.deltaTime;
            timeSkill      += Time.deltaTime;
            if (timeSkill >= 3)
            {
                fsm.Feed(OnCondition.SkillReady);
            }
            else
            {
                if (timeToAttack >= 0.5f)
                {
                    zoneAttack.gameObject.SetActive(false);
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1.5f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };

        skill.OnEnter += () =>
        {
            zoneAttack.gameObject.SetActive(true);
            Patrol();
            timeSkill = 0;
        };
        skill.OnUpdate += () =>
        {
            timeToSequence += Time.deltaTime;
            timeToAttack   += Time.deltaTime;

            if (timeToAttack >= 3f)
            {
                zoneAttack.gameObject.SetActive(false);
                bossSword.Attack(transform.position + transform.forward.normalized, transform.rotation, 10, target);
                //anim.SetFloat("Attack", 1);
                //anim.SetBool("Run", false);
            }
            if (timeToAttack > 4f)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };

        teletransport.OnEnter += () =>
        {
            Patrol();
            Instantiate(tpParticle, transform.position, transform.rotation);
        };
        teletransport.OnUpdate += () =>
        {
            StartCoroutine(ToState(OnCondition.Summon, 0.3f));
        };
        teletransport.OnExit += () =>
        {
            transform.position = tpPos.position;
            Instantiate(smoke, transform.position, Quaternion.Euler(-90, 0, 0));
        };

        summon.OnEnter += () =>
        {
        };
        summon.OnUpdate += () => StartCoroutine(ToState(OnCondition.Heal, 0.5f));
        summon.OnExit   += () =>
        {
            if (target != null)
            {
                transform.forward = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
            }

            Instantiate(littleSmoke, transform.position + transform.forward.normalized, transform.rotation);
            Instantiate(littleSmoke, transform.position + transform.forward.normalized + transform.right.normalized, transform.rotation);
            Instantiate(littleSmoke, transform.position + transform.forward.normalized - transform.right.normalized, transform.rotation);
            Vector3 posToSpawn = new Vector3(transform.position.x, 1.5f, transform.position.z);
            Instantiate(enemySummon, posToSpawn + transform.forward.normalized, transform.rotation);
            timeToSequence   = 0;
            cooldownSequence = cooldownSequence * 2;
        };

        heal.OnEnter  += () => Instantiate(healSpell, transform.position, transform.rotation);
        heal.OnUpdate += () =>
        {
            TakeDamage(-5, false);
            StartCoroutine(ToState(OnCondition.Idle, 4f));
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            portal.Invoke();
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.TP, teletransport);
        idle.AddTransition(OnCondition.Summon, teletransport);
        idle.AddTransition(OnCondition.Heal, heal);
        idle.AddTransition(OnCondition.Die, die);


        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.TP, teletransport);
        persuit.AddTransition(OnCondition.Summon, summon);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.TP, teletransport);
        attack.AddTransition(OnCondition.SkillReady, skill);
        attack.AddTransition(OnCondition.Die, die);

        skill.AddTransition(OnCondition.Idle, idle);
        skill.AddTransition(OnCondition.Die, die);

        teletransport.AddTransition(OnCondition.Idle, idle);
        teletransport.AddTransition(OnCondition.Summon, summon);
        teletransport.AddTransition(OnCondition.Die, die);

        summon.AddTransition(OnCondition.Idle, idle);
        summon.AddTransition(OnCondition.Heal, heal);
        summon.AddTransition(OnCondition.Attack, attack);
        summon.AddTransition(OnCondition.Die, die);

        heal.AddTransition(OnCondition.Idle, idle);
        heal.AddTransition(OnCondition.Die, idle);

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #11
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = FindObjectOfType <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();


        var idle    = new State <OnCondition>("Idle");
        var persuit = new State <OnCondition>("Persuit");
        var attack  = new State <OnCondition>("Attack");
        var dig     = new State <OnCondition>("Dig");
        var appear  = new State <OnCondition>("Appear");
        var die     = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (timeToSkill >= cooldownSequence && target != null)
            {
                fsm.Feed(OnCondition.Dig);
            }
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timeToSkill += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timeToSkill     += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    //dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    navMeshAgent.SetDestination(target.transform.position);
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };
        persuit.OnExit += () => navMeshAgent.SetDestination(transform.position);

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timeToAttack = 0;
        };
        attack.OnUpdate += () =>
        {
            timeToSkill  += Time.deltaTime;
            timeToAttack += Time.deltaTime;
            if (timeToSkill >= cooldownSequence)
            {
                fsm.Feed(OnCondition.Dig);
            }
            else
            {
                if (timeToAttack < 0.3f)
                {
                    Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, 0.09f);
                }

                if (timeToAttack >= 0.5f)
                {
                    anim.SetBool("Run", false);
                    anim.SetTrigger("Attack");
                }
                if (timeToAttack > 1f)
                {
                    fsm.Feed(OnCondition.Idle);
                }
            }
        };
        attack.OnExit += () =>
        {
            Patrol();
        };

        dig.OnEnter += () =>
        {
            timeToSkill       = 0;
            booleano          = true;
            myRedZoneInstance = Instantiate(redZone, transform.position - Vector3.up * 1.7f, transform.rotation);
            myRedZoneInstance.transform.Rotate(90, 0, 0);
            //transform.position = new Vector3(transform.position.x, 100000, transform.position.z);
            GetComponentInChildren <SkinnedMeshRenderer>().enabled = false;
            GetComponentInChildren <Weapon>().GetComponent <MeshRenderer>().enabled = false;
        };
        dig.OnUpdate += () =>
        {
            followingTime += Time.deltaTime;
            myRedZoneInstance.transform.position = Vector3.Lerp(myRedZoneInstance.transform.position, target.transform.position, 0.015f);
            if (followingTime >= timeToAppear)
            {
                fsm.Feed(OnCondition.Appear);
            }
        };
        dig.OnExit += () =>
        {
            GetComponentInChildren <SkinnedMeshRenderer>().enabled = true;
            GetComponentInChildren <Weapon>().GetComponent <MeshRenderer>().enabled = true;

            followingTime = 0;
        };

        appear.OnEnter += () =>
        {
            Instantiate(smoke, transform.position - Vector3.up * 1.5f, transform.rotation);
            transform.position = myRedZoneInstance.transform.position + Vector3.up * 30;
            Destroy(myRedZoneInstance);
        };
        appear.OnUpdate += () =>
        {
            //transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, 2.5f, transform.position.z), 0.08f);
            int        floorLayer = 1 << 9;
            RaycastHit hit;
            if (Physics.Raycast(transform.position, Vector3.down, out hit, 3, floorLayer))
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        appear.OnExit += () =>
        {
            if (Vector3.Distance(target.transform.position, transform.position) < 3)
            {
                Shake.instance.shake       = 0.08f;
                Shake.instance.shakeAmount = 0.1f;
                target.GetComponent <PlayerLife>().TakeDamage(500, false);
                Instantiate(smoke, transform.position - Vector3.up * 1.5f, transform.rotation);
                var exp = Instantiate(expansion, transform.position - Vector3.up * 1.5f, transform.rotation);
                //exp.transform.Rotate(90, 0, 0);
            }
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            if (GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>() != null)
            {
                GetComponentInChildren <Weapon>().gameObject.GetComponent <Collider>().enabled = false;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        //////////////////

        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Dig, dig);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Idle, idle);
        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.Dig, dig);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.Persuit, persuit);
        attack.AddTransition(OnCondition.Dig, dig);
        attack.AddTransition(OnCondition.Die, die);

        dig.AddTransition(OnCondition.Idle, idle);
        dig.AddTransition(OnCondition.Appear, appear);
        dig.AddTransition(OnCondition.Die, die);

        appear.AddTransition(OnCondition.Idle, idle);
        appear.AddTransition(OnCondition.Die, die);

        ///////////////

        fsm = new StateMachine <OnCondition>(idle);
    }
Пример #12
0
    public void Start()
    {
        dropWeapon = new EnemyWeaponDrop();
        SW         = new SpawnWeapon();
        var weaponTable = GameObject.Find("Weapon Table");

        wT            = weaponTable.GetComponent <WeaponTable>();
        xpPool        = FindObjectOfType <ExpParticlesPool>();
        expController = FindObjectOfType <ExpController>();

        var idle           = new State <OnCondition>("Idle");
        var persuit        = new State <OnCondition>("Persuit");
        var attack         = new State <OnCondition>("Attack");
        var meteorSkill    = new State <OnCondition>("Skill");
        var explotionSkill = new State <OnCondition>("Explotion");
        var die            = new State <OnCondition>("Dead");

        idle.OnUpdate += () =>
        {
            if (target != null)
            {
                fsm.Feed(OnCondition.Persuit);
                timerSecuence += Time.deltaTime;
            }
            else
            {
                Patrol();
            }
        };

        persuit.OnUpdate += () =>
        {
            if (target != null)
            {
                timerSecuence   += Time.deltaTime;
                distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                if (distanceToTarget < sight && distanceToTarget > range)
                {
                    aiAvoidance.CalculateVectors();
                    dirToGo += aiAvoidance.vectSeparacion + aiAvoidance.vectAvoidance;
                    anim.SetBool("Run", true);
                    transform.forward   = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    transform.position += transform.forward * 5 * Time.deltaTime;
                }
                else if (dirToGo.magnitude <= range)
                {
                    transform.forward = Vector3.Lerp(transform.forward, dirToGo, lerpSpeed);
                    fsm.Feed(OnCondition.Attack);
                }
            }
        };

        attack.OnEnter += () =>
        {
            sight = alertedSight;
            Patrol();
            timerAttack = 0;
            attacked    = false;
        };
        attack.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;
            timerSkill    += Time.deltaTime;
            if (timerAttack <= timeToAttack - 0.3f)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 1);
            }
            if (timerAttack >= timeToAttack && !attacked)
            {
                attacked = true;
                anim.SetBool("Run", false);
                anim.SetTrigger("Attack");
            }
            if (timerAttack > timeToAttack + 1)
            {
                fsm.Feed(OnCondition.Idle);
            }

            if (timerSkill > cooldownSequence && Vector3.Distance(target.transform.position, transform.position) < 3.5f)
            {
                fsm.Feed(OnCondition.ExplotionSkill);
            }
            else if (timerSkill >= cooldownSequence && meteoritesCount < 3)
            {
                fsm.Feed(OnCondition.Meteorites);
            }
        };

        meteorSkill.OnEnter += () =>
        {
            Patrol();
            timerSkill  = 0;
            timerAttack = 0;
            anim.speed  = 2;
        };
        meteorSkill.OnUpdate += () =>
        {
            timerSecuence += Time.deltaTime;
            timerAttack   += Time.deltaTime;

            if (timerAttack <= timeToAttack - 1)
            {
                Vector3 dirToGo = new Vector3(target.position.x - transform.position.x, 0, target.position.z - transform.position.z);
                transform.forward = Vector3.Lerp(transform.forward, dirToGo, 0.8f);
            }

            if (timerAttack > timeToAttack)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        meteorSkill.OnExit += () =>
        {
            var met = Instantiate(meteorite, target.transform.position + Vector3.up * 10, transform.rotation);
            met.GetComponent <Bomb>().dir     = (target.transform.position - met.transform.position).normalized;
            met.GetComponent <Bomb>().speed   = 0.05f;
            met.GetComponent <Bomb>().myLayer = 10;
            meteoritesCount++;
            cooldownSequence *= 2;
            timerSkill        = 0;
            timerAttack       = 0;
            anim.speed        = 1;
        };

        explotionSkill.OnEnter += () =>
        {
            Patrol();
            cirlceZone.SetActive(true);
        };
        explotionSkill.OnUpdate += () =>
        {
            timerToIdle += Time.deltaTime;
            if (timerToIdle >= 1f)
            {
                fsm.Feed(OnCondition.Idle);
            }
        };
        explotionSkill.OnExit += () =>
        {
            cirlceZone.SetActive(false);
            var fire = Instantiate(explotionFire, new Vector3(transform.position.x, 0.5f, transform.position.z), transform.rotation);
            fire.transform.Rotate(90, 0, 0);
            fire.GetComponent <MakeAreaDamage>().myLayer = 10;
            Shake.instance.shake       = 0.1f;
            Shake.instance.shakeAmount = 0.1f;
            timerToIdle = 0;
        };

        die.OnEnter += () =>
        {
            GetWeapon();
            for (int i = 0; i < 50; i++)
            {
                var p = xpPool.pool.GetObject();
                p.Spawn(new Vector3(transform.position.x, 0, transform.position.z));
                p.expController = this.expController;
            }
            Vector3 posToSpawn = new Vector3(transform.position.x, 0.5f, transform.position.z);
            Instantiate(itemToSpawn, posToSpawn, transform.rotation);
            portal.Invoke();
            DeactivateDoors(doorList);
            anim.speed = 0;
            var rends = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (var rend in rends)
            {
                rend.material.shader = dissolve;
            }
            Instantiate(deadParticle, transform.position, transform.rotation);
            GetComponent <Collider>().enabled = false;
            Destroy(this.gameObject, 3f);
        };

        idle.AddTransition(OnCondition.Persuit, persuit);
        idle.AddTransition(OnCondition.Attack, attack);
        idle.AddTransition(OnCondition.Meteorites, meteorSkill);
        idle.AddTransition(OnCondition.Die, die);

        persuit.AddTransition(OnCondition.Attack, attack);
        persuit.AddTransition(OnCondition.Meteorites, meteorSkill);
        persuit.AddTransition(OnCondition.Die, die);

        attack.AddTransition(OnCondition.Idle, idle);
        attack.AddTransition(OnCondition.ExplotionSkill, explotionSkill);
        attack.AddTransition(OnCondition.Meteorites, meteorSkill);
        attack.AddTransition(OnCondition.Die, die);

        meteorSkill.AddTransition(OnCondition.Idle, idle);
        meteorSkill.AddTransition(OnCondition.Die, die);
        meteorSkill.AddTransition(OnCondition.ExplotionSkill, explotionSkill);

        explotionSkill.AddTransition(OnCondition.Idle, idle);
        explotionSkill.AddTransition(OnCondition.Die, die);

        fsm = new StateMachine <OnCondition>(idle);
    }