/**
  * TODO: Description.
  *
  * @param service
  * @param config TODO.
  * @throws JsonValueException TODO.
  */
 public Policy(SynchronizationService service, JsonValue config) throws JsonValueException {
   this.service = service;
   situation = config.get("situation").required().asEnum(Situation.class);
   JsonValue action = config.get("action").required();
   if (action.isString()) {
     this.action = action.asEnum(Action.class);
     this.script = null;
     this.scriptScope = null;
   } else {
     this.action = null;
     this.script = Scripts.newInstance("Policy", action);
     if (action.isMap() && action.asMap().size() > 2) {
       // If there is additional attributes then copy them
       scriptScope = action.copy().asMap();
       scriptScope.remove("type");
       scriptScope.remove("source");
       scriptScope.remove("file");
     } else {
       scriptScope = null;
     }
   }
   JsonValue pAction = config.get("postAction");
   if (pAction.isNull()) {
     this.postAction = null;
   } else {
     this.postAction = Scripts.newInstance("PostAction", pAction);
   }
 }
Пример #2
0
  public static void initWildLife() {
    Thing t;

    t = Lib.extend("rabbit", "base animal");
    t.set("IsHostile", 0);
    t.set("Image", 285);
    t.set("IsOwned", 1);
    t.set("MoveSpeed", 140);
    Monster.stats(t, 3, 2, 15, 3, 1, 2, 1, 1);
    t.set("DeathDecoration", "piece of rabbit meat");
    Lib.add(t);

    t = Lib.extend("hare", "rabbit");
    t.set("MoveSpeed", 240);
    Monster.stats(t, 3, 2, 25, 3, 1, 2, 1, 1);
    t.set("DeathDecoration", "piece of hare meat");
    Lib.add(t);

    t = Lib.extend("butterfly", "base animal");
    t.set("IsHostile", 0);
    t.set("IsBlocking", 0);
    t.set("Image", 294);
    t.set("IsItem", 1);
    t.set("DeathDecoration", null);
    t.set("ItemWeight", 100);
    Monster.stats(t, 1, 1, 5, 1, 1, 1, 1, 1);
    Lib.add(t);

    t = Lib.extend("snail", "base animal");
    t.set("IsHostile", 0);
    t.set("IsOwned", 1);
    t.set("Image", 387);
    t.set("MoveSpeed", 40);
    Monster.stats(t, 1, 1, 5, 1, 1, 1, 1, 1);
    t.set("DeathDecoration", "slime pool");
    Lib.add(t);

    t = Lib.extend("escargot", "base animal");
    t.set("IsHostile", 0);
    t.set("IsOwned", 1);
    t.set("Image", 387);
    t.set("MoveSpeed", 40);
    Monster.stats(t, 1, 1, 5, 1, 1, 1, 1, 1);
    t.set("DeathDecoration", "escargot steak");
    t.set("ASCII", "e");
    Lib.add(t);

    t = Lib.extend("slug", "base animal");
    t.set("IsHostile", 0);
    t.set("Image", 386);
    t.set("MoveSpeed", 40);
    Monster.stats(t, 1, 1, 5, 1, 1, 1, 1, 1);
    t.set("DeathDecoration", "poison cloud");
    Lib.add(t);

    t = Lib.extend("flutterby", "butterfly");
    t.set("DecayRate", 1000);
    t.addHandler("OnAction", Scripts.decay());
    Lib.add(t);
  }
  // PAS FINI ?
  @Override
  public boolean createUser(User user) throws SQLException {
    if (SQLSettings.getPDS() == null) System.err.println("getPDS() not started.");
    ResultSet rset = null;
    int rset2;
    Statement stmt = null;
    Connection connection = null;

    try {
      connection = SQLSettings.getPDS().getConnection();
      stmt = connection.createStatement();
      String encryptedPass = null;

      rset = stmt.executeQuery("select PASSWORD('" + user.getPassword() + "') ;");
      if (rset != null) {
        while (rset.next()) {
          encryptedPass = rset.getString(1);
        }
        rset2 =
            stmt.executeUpdate(
                "create user '"
                    + user.getLogin()
                    + "'@'%' IDENTIFIED BY PASSWORD '"
                    + encryptedPass
                    + "' ;");

        String[] viewCommand = Scripts.getCreateUserViews(user);
        // On cree les vues utilisateur et on donne les acces
        for (String curcom : viewCommand) rset2 = stmt.executeUpdate(curcom);

        // on insere le tuple dans user_view
        UserViewDAO uvdao = new MySQLUserViewDAO();
        uvdao.addUserView(user.getLogin(), user.getId());

        return true;
      }

      return false;

    } catch (SQLException e) {
      e.printStackTrace();
      throw e;
    } finally {
      try {
        if (rset != null) rset.close();
      } catch (Exception e) {
      }
      ;
      try {
        if (stmt != null) stmt.close();
      } catch (Exception e) {
      }
      ;
      try {
        if (connection != null) connection.close();
      } catch (Exception e) {
      }
      ;
    }
  }
  // PAS FINI ?
  @Override
  public boolean removeUser(User user) throws SQLException {
    if (SQLSettings.getPDS() == null) System.err.println("getPDS() not started.");
    int rset2;
    Statement stmt = null;
    Connection connection = null;

    try {
      connection = SQLSettings.getPDS().getConnection();
      stmt = connection.createStatement();

      String[] viewCommand = Scripts.getDeleteUserViews(user);
      // On supprime les vues utilisateur et  acces
      for (String curcom : viewCommand) rset2 = stmt.executeUpdate(curcom);
      connection = SQLSettings.getPDS().getConnection();
      stmt = connection.createStatement();
      stmt.execute("DROP USER " + user.getLogin() + " ;");
      connection = SQLSettings.getPDS().getConnection();
      stmt = connection.createStatement();
      stmt.execute("DROP USER " + user.getLogin() + "@'' ;");

      // on enleve le tuple de user_view
      UserViewDAO uvdao = new MySQLUserViewDAO();
      uvdao.removeUser(user);

      return true;

    } catch (SQLException e) {
      e.printStackTrace();
      throw e;
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (Exception e) {
      }
      ;
      try {
        if (connection != null) connection.close();
      } catch (Exception e) {
      }
      ;
    }
  }
Пример #5
0
  public static void init() {
    Thing t;

    t = Lib.extend("base poison", "temporary effect");
    t.set("IsActive", 1);
    t.addHandler("OnAction", new PoisonAction());
    t.set("IsPoison", 1);
    t.set("DamageType", "poison");
    t.set("EffectName", "poisoned");
    t.set("ResistStat", "TG");
    t.set("ResistMessage", null);
    t.set("ResistDifficulty", 10);
    t.set("CureDifficulty", 5);
    Lib.add(t);

    t = Lib.extend("weakening poison", "base poison");
    t.set("LifeTime", 50000);
    t.set("EffectName", "poisoned");
    t.set("Strength", 100);
    t.set("Damage", 2);
    t.set("DamageType", "poison");
    t.set("DamageMessage", "You feel sick...");
    t.set("ResistMessage", "You manage to shake off a feeling of weakness");
    t.set("AttributeAddMessage", "You feel weakened!");
    t.add("CarriedModifiers", Modifier.linear("ST", 90, 0));
    Lib.add(t);

    t = Lib.extend("poison", "base poison");
    t.set("LifeTime", 20000);
    t.set("Strength", 200);
    t.set("Damage", 3);
    t.set("DamageType", "poison");
    t.set("ResistMessage", "You feel queasy for a moment");
    t.set("DamageMessage", "You feel the effects of poison...");
    t.set("AttributeAddMessage", "You feel poisoned!");
    Lib.add(t);

    t = Lib.extend("strong poison", "base poison");
    t.set("LifeTime", 30000);
    t.set("Strength", 300);
    t.set("Damage", 6);
    t.set("DamageType", "poison");
    t.set("ResistMessage", "You feel very queasy for a moment");
    t.set("DamageMessage", "You feel the poison weakening you...");
    t.set("AttributeAddMessage", "You feel badly poisoned!");
    t.set("CureDifficulty", 15);
    Lib.add(t);

    t = Lib.extend("deadly poison", "base poison");
    t.set("LifeTime", 40000);
    t.set("Strength", 2000);
    t.set("Damage", 10);
    t.set("DamageType", "poison");
    t.set("ResistMessage", "You feel very queasy for a moment");
    t.set("DamageMessage", "You feel the poison weakening you...");
    t.set("AttributeAddMessage", "You feel badly poisoned!");
    t.set("CureDifficulty", 40);
    Lib.add(t);

    t = Lib.extend("extreme poison", "base poison");
    t.set("LifeTime", 50000);
    t.set("Strength", 6000);
    t.set("Damage", 15);
    t.set("DamageType", "poison");
    t.set("ResistMessage", "You feel very queasy for a moment");
    t.set("DamageMessage", "You feel the poison weakening you...");
    t.set("AttributeAddMessage", "You feel badly poisoned!");
    t.set("CureDifficulty", 100);
    Lib.add(t);

    t = Lib.extend("ultimate poison", "base poison");
    t.set("LifeTime", 100000);
    t.set("Strength", 12000);
    t.set("Damage", 30);
    t.set("DamageType", "poison");
    t.set("ResistMessage", "You feel very queasy for a moment");
    t.set("DamageMessage", "You feel the poison weakening you...");
    t.set("AttributeAddMessage", "You feel badly poisoned!");
    t.set("CureDifficulty", 300);
    Lib.add(t);

    t = Lib.extend("sickness", "base poison");
    t.set("LifeTime", 50000);
    t.set("Strength", 100);
    t.set("Damage", 2);
    t.set("DamageType", "poison");
    t.set("DamageMessage", "You feel sick...");
    t.set("ResistMessage", "You manage to shake off a feeling of illness");
    t.set("AttributeAddMessage", "You feel sick!");
    t.add("CarriedModifiers", Modifier.bonus("ST", -2));
    t.add("CarriedModifiers", Modifier.bonus("SK", -2));
    t.set("CureDifficulty", 15);
    Lib.add(t);

    t = Lib.extend("pestilence", "poison");
    t.set("LifeTime", 120000);
    t.set("Strength", 200);
    t.set("Damage", 4);
    t.set("EffectName", "pestilent");
    t.set("DamageType", "poison");
    t.set("DamageMessage", "You feel grotty...");
    t.set("AttributeAddMessage", "You feel the touch of pestilence!");
    t.set("ResistDifficulty", 20);
    t.addHandler("OnAction", Scripts.generator("fly swarm", 100));
    t.set("CureDifficulty", 25);
    Lib.add(t);

    t = Lib.extend("plague", "poison");
    t.set("LifeTime", 100000);
    t.set("Strength", 200);
    t.set("Damage", 8);
    t.set("EffectName", "plague");
    t.set("DamageType", "poison");
    t.set("DamageMessage", "You feel sick...");
    t.set("AttributeAddMessage", "You feel the touch of the plague!");
    t.set("ResistDifficulty", 20);
    t.add("CarriedModifiers", Modifier.linear("CH", 100, -10));
    t.addHandler("OnAction", Scripts.generator("plague cloud", 30));
    t.set("CureDifficulty", 100);
    Lib.add(t);
  }