public FactionCommand(MafiaGame game, VillageMember member, Power power)
        {
            this.game = game;
            this.member = member;
            this.power = power;

            this.name = power.Name;
            this.allowedInPublic = false;
        }
        public PowerCommand(MafiaGame game, VillageMember member, Power power)
        {
            this.game = game;
            this.member = member;
            this.power = power;

            this.name = power.Name;
            this.allowedInPublic = publicCommands.Contains(power.Name.ToLower());
        }
Exemple #3
0
        public VillageMember CreateMember(string name, string role)
        {
            Log.Debug("Creating member of faction " + this.Name + " (" + name + "," + role + ")");

            VillageMember member = new VillageMember(Village, role);
            member.Name = name;
            member.Faction = this;
            RoleManager.Instance.InitRole(member, role);
            this.Members.Add(member);

            Village.Rules.MaximumPopulation = Village.Members.Count;

            return member;
        }
Exemple #4
0
        public MafiaUser(MafiaGame game, NetUser user, VillageMember member)
        {
            this.user = user;
            this.game = game;
            this.member = member;

            AddMafiaCommands();

            member.PowerGained += new EventHandler<PowerEventArgs>(OnPowerGained);
            member.PowerLost += new EventHandler<PowerEventArgs>(OnPowerLost);

            member.Faction.PowerGained += new EventHandler<PowerEventArgs>(OnFactionPowerGained);
            member.Faction.PowerLost += new EventHandler<PowerEventArgs>(OnFactionPowerLost);
        }
Exemple #5
0
        public void InitRole(VillageMember member, string roleName)
        {
            if(!roles.ContainsKey(roleName)) {
                throw new NoSuchRoleException("There is no role with the name " + roleName);
            }

            RoleInfo role = roles[roleName];

            if(role.Inherits != null) {
                InitRole(member, role.Inherits);
            }

            member.RoleName = role.Name;

            foreach(RoleInfo.PowerInfo powerInfo in role.Powers) {
                List<object> args = new List<object>();

                object power;
                if (powerInfo.Type == RoleInfo.PowerType.Effect) {
                    args.Add(member);
                }
                if (powerInfo.Args.Count > 0) {
                    args.Add(powerInfo.Args);
                }
                power = powerInfo.PowerType.InvokeMember("", BindingFlags.CreateInstance, null, null, args.ToArray());

                if(powerInfo.Duration != 0) {
                    if (power is Effect) {
                        (power as Effect).Duration = powerInfo.Duration;
                    }
                    else {
                        (power as Power).Charges = powerInfo.Duration;
                    }
                }

                if(powerInfo.Type == RoleInfo.PowerType.Power) {
                    member.AddPower((Power)power);
                }
                else {
                    member.ApplyEffect((Effect)power);
                }
            }

            if(role.ShowsAs != null) {
                member.RoleName = role.ShowsAs;
            }
        }
Exemple #6
0
        public void RemoveMember(VillageMember member)
        {
            members.Remove(member);
            if (Village != null) {
                Village.Members.Remove(member);
            }

            Village.Rules.MaximumPopulation = Village.Members.Count;
        }
Exemple #7
0
        public Action UsePower(Power power, VillageMember initiator, Actor target)
        {
            if (target != null) {
                Log.Debug(this.Name + " uses power " + power.GetType().Name + " on " + target.Name);
            }
            else {
                Log.Debug(this.Name + " uses power " + power.GetType().Name);
            }

            if (target is VillageMember) {
                if (((VillageMember)target).State == MemberState.Dead) {
                    throw new TargetIsDeadException(target.Name + " is dead.");
                }
            }

            Action action = new Action(power, this, initiator, target);
            try {
                action.Prepare();
                village.RaiseActionPrepared(action);
                if (action.Power.Instant) {
                    action.Who.RaisePreActionSource(action);
                    if (action.Target != null) {
                        action.Target.RaisePreActionTarget(action);
                    }
                    if (action.Cancel) {
                        Log.Debug("Action cancelled.");
                    } else {
                        Log.Debug("Executing action...");
                        action.Execute();

                        action.Who.RaisePostActionSource(action);
                        if (action.Target != null) {
                            action.Target.RaisePostActionTarget(action);
                        }
                        if (action.Result != null) {
                            action.Result.Apply();
                        }
                    }
                }
                else {
                    Log.Debug("Queueing " + power.GetType().FullName + " on " + target.Name);
                    village.Phase.QueueAction(action);
                    action.ResultMessage = String.Format(power.QueuedMessage, target.Name);
                }
                village.RaiseActionExecuted(action);
                return action;
            }
            catch (Action.ActionException ex) {
                action.ResultMessage = ex.Message;
                action.Cancel = true;
                return action;
            }
        }
Exemple #8
0
 public Action UsePower(string powerName, VillageMember initiator, Actor target)
 {
     Power power = GetPower(powerName);
     if(power == null) {
         throw new NoSuchPowerException("You do not have the power " + powerName);
     }
     return UsePower(power, initiator, target);
 }
 public VillageMemberEventArgs(VillageMember member)
 {
     this.member = member;
 }