예제 #1
0
    /// <summary>
    /// Method that deserializes the data from the line starting at given position in given context depending on the MessageType
    /// </summary>
    /// <param id="mt">MessageType defining the extend of deserialization which is to be performed</param>
    /// <param id="line">String array containing the serialized data</param>
    /// <param id="position">Current position in the array</param>
    /// <param id="context">Context of the serialized data, game where this INetworkSerializable object is in</param>
    public virtual void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
    {
      string entry;
      switch (mt)
      {
        case MessageType.GameTransfer:
        case MessageType.GameEffectCreate:
          entry = line[position++];
          if (entry != Db.NOENTRY) { Entry = Db.Instance.Effects[entry]; }
          else { Entry = null; }
          Speed = int.Parse(line[position++]);
          Duration = int.Parse(line[position++]);
          Time = int.Parse(line[position++]);
          UpdateOffset = ((long.Parse(line[position++]) - UI.Instance.UpdateNumber)) % Speed;
          int tx = int.Parse(line[position++]);
          int ty = int.Parse(line[position++]);
          if (tx == -1 && ty == -1)
            Tile = null;
          else
            Tile = context.Map.Tiles[tx, ty];

          Graphical = line[position++] == "1";
          GraphicalOverlay = line[position++] == "1";

          string target = line[position++];
          if (target != "null") { targetEntity = context.GetGameObjectById(int.Parse(line[position++])); }
          target = line[position++];
          if (target != "null") { targetTile = context.Map.Tiles[int.Parse(target), int.Parse(line[position++])]; }

          int eLocalCount = int.Parse(line[position++]);
          LocalData = new List<object>();
          for (int i = 0; i < eLocalCount; i++)
          {
            target = line[position++];
            if (target == "g") { LocalData.Add(context.GetGameObjectById(int.Parse(line[position++]))); }
            else if (target == "t") { LocalData.Add(context.Map.Tiles[int.Parse(line[position++]), int.Parse(line[position++])]); }
            else { LocalData.Add(line[position++]); }
          }

          break;
        default:
          throw new Exception("GameEffect deserialization error");
      }
    }
예제 #2
0
    /// <summary>
    /// Initialize the GameEffect
    /// </summary>
    /// <param id="game">game this effect belongs to</param>
    /// <param id="tile"></param>
    public virtual void Initialize(WildmenGame game, Tile tile)
    {
      this.game = game;
      this.Tile = tile;

      if (Entry != null)
      {
        if (Entry.Spell.OnSpellStartGameEntity != null && Entry.Spell.Target == SpellEntry.TargetType.GameEntity)
        {
          Entry.Spell.OnSpellStartGameEntity(game, this, caster, targetEntity);
        }
        else if (Entry.Spell.OnSpellStartTile != null && Entry.Spell.Target == SpellEntry.TargetType.Tile)
        {
          Entry.Spell.OnSpellStartTile(game, this, caster, targetTile);
        }
      }

      targetEntity = null;
      targetTile = null;

      UpdateOffset = -UI.Instance.UpdateNumber % Speed;
      UpdateOffset++;

    }
예제 #3
0
    //

    /// <summary>
    /// Disposes resources used by this instance
    /// </summary>
    public virtual void Dispose()
    {
      Entry = null;
      game = null;
      LocalData = null;
      targetTile = null;
      targetEntity = null;
    }
예제 #4
0
 /// <summary>
 /// Constructor for scripted GameEffect
 /// </summary>
 /// <param id="effect">The effect database entry</param>
 /// <param id="caster">The caster of the spell</param>
 /// <param id="target">Target game entity for the effect</param>
 public GameEffect(EffectDb effect, IScriptUnit caster, IScriptGameEntity target)
 {
   this.targetEntity = target;
   this.Entry = effect;
   this.caster = caster;
   LocalData = new List<object>();
   Active = true;
   Time = 0;
   Graphical = false;
   GraphicalOverlay = false;
 }