Beispiel #1
0
        public void Execute()
        {
            try {
                bool       exec = false;
                InvokeMode mode = InvokeMode.im_ItSelf;

                switch (Action)
                {
                case EffectAction.ea_Instant:
                    // dummy
                    break;

                case EffectAction.ea_Persistent:
                    exec = (Duration == 1);
                    mode = InvokeMode.im_FinAction;
                    break;

                case EffectAction.ea_EachTurn:
                    exec = true;
                    break;

                case EffectAction.ea_RandomTurn:
                    exec = AuxUtils.Chance(10);
                    break;

                case EffectAction.ea_LastTurn:
                    exec = (Duration == 1);
                    break;
                }

                if (exec)
                {
                    EffectID eid = (EffectID)CLSID;

                    if (this is MapEffect)
                    {
                        EffectExt ext = ((MapEffect)this).Ext;
                        InvokeEffect(eid, null, Source, mode, EffectAction.ea_Instant, ext);
                    }
                    else
                    {
                        NWCreature creature   = (NWCreature)Owner;
                        int        lid        = (creature.CurrentField).LandID;
                        bool       LocusValid = (eid == EffectID.eid_Relocation) && creature.IsPlayer && creature.Effects.FindEffectByID(EffectID.eid_LocusMastery) != null && lid != GlobalVars.Land_Valhalla && lid != GlobalVars.Land_Vigrid && lid != GlobalVars.Land_Bifrost && lid != GlobalVars.Land_Nidavellir && lid != GlobalVars.Land_Niflheim && lid != GlobalVars.Land_Ocean;
                        if (LocusValid)
                        {
                            EffectExt ext = new EffectExt();
                            ext.ReqParams = new EffectParams(EffectParams.ep_Place);
                            GlobalVars.nwrWin.InitTarget(EffectID.eid_Relocation, null, mode, ext);
                        }
                        else
                        {
                            creature.UseEffect(eid, Source, mode, null);
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Write("Effect.execute(): " + ex.Message);
            }
        }
Beispiel #2
0
        public static bool InitParams(EffectID effectID, LocatedEntity creature, object source, InvokeMode invokeMode, ref EffectExt refExt)
        {
            if (refExt == null)
            {
                refExt = new EffectExt();
            }

            refExt.ReqParams = EffectsData.dbEffects[(int)effectID].ReqParams;
            ICheckProc proc = EffectsData.dbEffectProcs[(int)effectID].Check;

            if (proc != null)
            {
                proc.Invoke(effectID, (NWCreature)creature, source, invokeMode, refExt);
            }

            return(refExt.Valid);
        }
Beispiel #3
0
        public static void InvokeEffect(EffectID effectID, LocatedEntity creature, object source, InvokeMode invokeMode, EffectAction action, EffectExt ext)
        {
            if (effectID == EffectID.eid_None)
            {
                return;
            }

            try {
                if (creature != null)
                {
                    GameEvent @event = new GameEvent(GameSpace.Instance, null);
                    @event.CLSID = (int)effectID;
                    @event.SetPos(creature.PosX, creature.PosY);
                    GlobalVars.nwrWin.DoEvent(EventID.event_EffectSound, null, null, @event);
                    @event.Dispose();
                }

                ItemState state;
                if (source != null && source is Item)
                {
                    state = ((Item)source).State;
                }
                else
                {
                    state = ItemState.is_Normal;
                }

                bool valid = (ext == null || ext.Valid);
                if (valid)
                {
                    IEffectProc proc = EffectsData.dbEffectProcs[(int)effectID].Proc;
                    if (proc != null)
                    {
                        proc.Invoke(effectID, (NWCreature)creature, source, state, invokeMode, ext);
                    }
                }
            } catch (Exception ex) {
                //EffectsData.dbEffects[(int)effectID]
                string msg = "Effect.invokeEffect(): " + effectID.ToString();
                if (creature != null)
                {
                    msg = msg + "/" + ((NWCreature)creature).Entry.Sign;
                }
                if (source != null && source is Item)
                {
                    msg = msg + "/" + ((Item)source).Entry.Sign;
                }
                msg = msg + ", " + ex.Message;
                Logger.Write(msg);
            }
        }