Exemplo n.º 1
0
        public void GiveJobTo(Job job, Character newHolder, Game game)
        {
            if(job.Unique)
            {
                Character oldHolder = uniqueJobs[job];

                if(oldHolder != null)
                {
                    if (job.Permanent)
                        throw new InvalidOperationException("You tried to fire the king!! He chops your head off instead.");

                    oldHolder.FireFromJob(job);

                    Event fireEvent = game.GetEventById(job.OnFire);
                    if (fireEvent != null)
                    {
                        EventContext context = new EventContext(oldHolder);
                        fireEvent.Execute(new EventResults(), game, context);
                        //We need to commit any changes.
                        context.Commit();
                    }
                }

                if(newHolder != null)
                {
                    newHolder.GiveJob(job);

                    Event hireEvent = game.GetEventById(job.OnHire);
                    if (hireEvent != null)
                    {
                        EventContext context = new EventContext(newHolder);
                        hireEvent.Execute(new EventResults(), game, context);
                        //We need to commit any changes.
                        context.Commit();
                    }
                }

                uniqueJobs[job] = newHolder;
            }
            else
            {
                if(newHolder != null)
                {
                    newHolder.GiveJob(job);

                    Event hireEvent = game.GetEventById(job.OnHire);
                    if (hireEvent != null)
                    {
                        EventContext context = new EventContext(newHolder);
                        hireEvent.Execute(new EventResults(), game, context);
                        //We need to commit any changes.
                        context.Commit();
                    }
                }
            }
        }