public void OnCreated(CreationEventArgs e)
        {
            CreationEventHandler temp = Created;

            if (temp != null)
            {
                temp(this, e);
            }
        }
Example #2
0
 // do RNG on list of locations
 public override void Act(CAEntity entity)
 {
     if (entity is CAGraphCellAgent agent)
     {
         if (agent.Parent.Parent.Parent.GetRandomDouble() < this.Probability)
         {
             var Graph = agent.Parent.Parent;
             List <CAGraphCell> realLocations = new List <CAGraphCell>();
             var locations = Location.GetLocations(agent);
             for (int i = 0; i < locations.Length; i++)
             {
                 var cell = Graph.GetCell(locations[i]);
                 if (cell != null)
                 {
                     if (!cell.ContainsAgent())
                     {
                         realLocations.Add(cell);
                         Success?.Invoke(this, new CreationEventArgs(CreationEventArgs.CreationStatus.Success, locations[i], cell));
                     }
                     else
                     {
                         Failure?.Invoke(this, new CreationEventArgs(CreationEventArgs.CreationStatus.Failure_AgentExists, locations[i], cell));
                     }
                 }
                 else
                 {
                     Failure?.Invoke(this, new CreationEventArgs(CreationEventArgs.CreationStatus.Failure_CellNull, locations[i]));
                 }
             }
             if (realLocations.Count > 0)
             {
                 int select = (int)Math.Floor(agent.Parent.Parent.Parent.GetRandomDouble() * realLocations.Count);
                 CAGraphCellAgent newAgent = new CAGraphCellAgent(realLocations[select], State);
                 realLocations[select].AddAgent(newAgent);
                 Success?.Invoke(this, new CreationEventArgs(CreationEventArgs.CreationStatus.Success, realLocations[select].Position, realLocations[select]));
             }
             else
             {
                 Failure?.Invoke(this, new CreationEventArgs(CreationEventArgs.CreationStatus.Failure_NoLocations, (ushort.MaxValue, ushort.MaxValue, ushort.MaxValue)));
             }
         }
     }
 }
Example #3
0
 private void OnCreatedClientInstance(object sender, CreationEventArgs e)
 {
     Invoke(new Action(() =>
     {
         statusProgress.Visible = true;
         statusProgress.Style   = ProgressBarStyle.Continuous;
         statusProgress.Value   = 100;
         if (e.IsSuccessful)
         {
             mainMenuDisconnect.Enabled = true;
             ClientController.InitializeConnection();
         }
     }));
 }
Example #4
0
        /// <summary>
        /// Updates Create objectives.
        /// </summary>
        /// <remarks>
        /// Creation and Production events share same event
        /// due to having the same ObjectiveType code.
        /// </remarks>
        /// <param name="args">An object of type CreationEventArgs or ProductionEventArgs, otherwise an exception will be issued to the logger.</param>
        private void OnCreatureCreatedOrProducedItem(EventArgs args)
        {
            Creature creature;
            int      itemId;
            string   skill;           // Is there a better way to check for skill match?

            CreationEventArgs   crargs = args as CreationEventArgs;
            ProductionEventArgs prargs = args as ProductionEventArgs;

            if (crargs != null)             // Try cast as CreationEventArgs
            {
                creature = crargs.Creature;
                itemId   = crargs.Item.Info.Id;
                skill    = crargs.Method.ToString();
            }
            else if (prargs != null)             // Try cast as ProductionEventArgs
            {
                // Cancel if it wasn't a success
                if (!prargs.Success)
                {
                    return;
                }

                creature = prargs.Creature;
                itemId   = prargs.ProductionData.ItemId;               // Use production data in case Item is null
                skill    = prargs.ProductionData.Category.ToString();
                if (skill == "Spinning")
                {
                    skill = "Weaving";                     // Shared SkillId.
                }
            }
            else             // Error: Cannot cast as either one.
            {
                Log.Exception(new InvalidCastException(String.Format("Unable to cast EventArgs as CreationEventArgs nor ProductionEventArgs (Quest Name: {0}, ID: {1})", this.Name, this.Id)));
                return;
            }

            var quests = creature.Quests.GetAllIncomplete(this.Id);

            foreach (var quest in quests)
            {
                if (!this.CanMakeProgress(creature, quest))
                {
                    continue;
                }

                var progress = quest.CurrentObjectiveOrLast;
                if (progress == null)
                {
                    return;
                }

                var objective = this.Objectives[progress.Ident];
                if (objective == null || objective.Type != ObjectiveType.Create)
                {
                    return;
                }

                var createObjective = (objective as QuestObjectiveCreate);
                if (!progress.Done && itemId == createObjective.ItemId && skill == createObjective.SkillId.ToString())
                {
                    var done = (++progress.Count == createObjective.Amount);
                    if (done)
                    {
                        quest.SetDone(progress.Ident);
                    }

                    UpdateQuest(creature, quest);

                    // Hot-fix for #390, after a creation objective might
                    // come a collect objective for the finished items,
                    // the new active objective has to be checked.
                    // This should happen generally, but some refactoring is
                    // in order, to not make such a mess out of it.
                    if (done)
                    {
                        this.CheckCurrentObjective(creature);
                    }
                }
            }
        }
Example #5
0
		/// <summary>
		/// Raised when creature creates an item, handles creation conditions.
		/// </summary>
		/// <param name="args"></param>
		private void OnCreatureCreatedItem(CreationEventArgs args)
		{
			var skill = args.Creature.Skills.Get(SkillId.ProductionMastery);
			if (skill == null) return;

			if (skill.Info.Rank == SkillRank.R5)
			{
				if (args.Rank >= SkillRank.R7 && args.Rank <= SkillRank.R5)
				{
					if (args.Method == CreationMethod.Tailoring)
						skill.Train(6); // Successfully tailor any item from Rank 7 to Rank 5.
					else if (args.Method == CreationMethod.Blacksmithing)
						skill.Train(7); // Successfully smith any item from Rank 7 to Rank 5.
				}
				return;
			}

			if (skill.Info.Rank == SkillRank.R4)
			{
				if (args.Rank >= SkillRank.R6 && args.Rank <= SkillRank.R4)
				{
					if (args.Method == CreationMethod.Tailoring)
						skill.Train(6); // Successfully tailor any item from Rank 6 to Rank 4.
					else if (args.Method == CreationMethod.Blacksmithing)
						skill.Train(7); // Successfully smith any item from Rank 6 to Rank 4.
				}
				return;
			}

			if (skill.Info.Rank == SkillRank.R3)
			{
				if (args.Rank >= SkillRank.R5 && args.Rank <= SkillRank.R3)
				{
					if (args.Method == CreationMethod.Tailoring)
						skill.Train(6); // Successfully tailor any item from Rank 5 to Rank 3.
					else if (args.Method == CreationMethod.Blacksmithing)
						skill.Train(7); // Successfully smith any item from Rank 5 to Rank 3.
				}
				return;
			}

			if (skill.Info.Rank == SkillRank.R2)
			{
				if (args.Rank >= SkillRank.R4 && args.Rank <= SkillRank.R2)
				{
					if (args.Method == CreationMethod.Tailoring)
						skill.Train(6); // Successfully tailor any item from Rank 4 to Rank 2.
					else if (args.Method == CreationMethod.Blacksmithing)
						skill.Train(7); // Successfully smith any item from Rank 4 to Rank 2.
				}
				return;
			}

			if (skill.Info.Rank == SkillRank.R1)
			{
				if (args.Rank >= SkillRank.R3 && args.Rank <= SkillRank.R1)
				{
					if (args.Method == CreationMethod.Tailoring)
						skill.Train(5); // Successfully tailor any item from Rank 3 to Rank 1.
					else if (args.Method == CreationMethod.Blacksmithing)
						skill.Train(6); // Successfully smith any item from Rank 3 to Rank 1.
				}
				return;
			}
		}
Example #6
0
        /// <summary>
        /// Raised when creature creates an item, handles creation conditions.
        /// </summary>
        /// <param name="args"></param>
        private void OnCreatureCreatedItem(CreationEventArgs args)
        {
            var skill = args.Creature.Skills.Get(SkillId.ProductionMastery);

            if (skill == null)
            {
                return;
            }

            if (skill.Info.Rank == SkillRank.R5)
            {
                if (args.Rank >= SkillRank.R7 && args.Rank <= SkillRank.R5)
                {
                    if (args.Method == CreationMethod.Tailoring)
                    {
                        skill.Train(6);                         // Successfully tailor any item from Rank 7 to Rank 5.
                    }
                    else if (args.Method == CreationMethod.Blacksmithing)
                    {
                        skill.Train(7);                         // Successfully smith any item from Rank 7 to Rank 5.
                    }
                }
                return;
            }

            if (skill.Info.Rank == SkillRank.R4)
            {
                if (args.Rank >= SkillRank.R6 && args.Rank <= SkillRank.R4)
                {
                    if (args.Method == CreationMethod.Tailoring)
                    {
                        skill.Train(6);                         // Successfully tailor any item from Rank 6 to Rank 4.
                    }
                    else if (args.Method == CreationMethod.Blacksmithing)
                    {
                        skill.Train(7);                         // Successfully smith any item from Rank 6 to Rank 4.
                    }
                }
                return;
            }

            if (skill.Info.Rank == SkillRank.R3)
            {
                if (args.Rank >= SkillRank.R5 && args.Rank <= SkillRank.R3)
                {
                    if (args.Method == CreationMethod.Tailoring)
                    {
                        skill.Train(6);                         // Successfully tailor any item from Rank 5 to Rank 3.
                    }
                    else if (args.Method == CreationMethod.Blacksmithing)
                    {
                        skill.Train(7);                         // Successfully smith any item from Rank 5 to Rank 3.
                    }
                }
                return;
            }

            if (skill.Info.Rank == SkillRank.R2)
            {
                if (args.Rank >= SkillRank.R4 && args.Rank <= SkillRank.R2)
                {
                    if (args.Method == CreationMethod.Tailoring)
                    {
                        skill.Train(6);                         // Successfully tailor any item from Rank 4 to Rank 2.
                    }
                    else if (args.Method == CreationMethod.Blacksmithing)
                    {
                        skill.Train(7);                         // Successfully smith any item from Rank 4 to Rank 2.
                    }
                }
                return;
            }

            if (skill.Info.Rank == SkillRank.R1)
            {
                if (args.Rank >= SkillRank.R3 && args.Rank <= SkillRank.R1)
                {
                    if (args.Method == CreationMethod.Tailoring)
                    {
                        skill.Train(5);                         // Successfully tailor any item from Rank 3 to Rank 1.
                    }
                    else if (args.Method == CreationMethod.Blacksmithing)
                    {
                        skill.Train(6);                         // Successfully smith any item from Rank 3 to Rank 1.
                    }
                }
                return;
            }
        }
 private void ReactionType_Created(object sender, CreationEventArgs e)
 {
     CreatedAt = DateTime.Now;
 }