Package com.l2client.controller.entity

Examples of com.l2client.controller.entity.EntityManager


    return singleton;
  }

  @Override
  public void onUpdateOf(Component c, float tpf) {
    EntityManager em = Singleton.get().getEntityManager();
    if(c instanceof TargetComponent){
      TargetComponent tgt = (TargetComponent)c;
      L2JComponent l2j = (L2JComponent)em.getComponent(em.getEntityId(tgt),L2JComponent.class);
      if(l2j != null && !l2j.isPlayer) {
        //
        // NPC UPDATE
        if(tgt.getCurrentTarget() != tgt.getLastTarget()){ 
          //reset targeting creation changes by setting old target to current
          tgt.setTarget(tgt.getCurrentTarget());
        } else {
          //update position only
          //check if target is set and moved out of distance
          if(!tgt.hasTarget())
            return;
          //TODO distance check only on client side? server still has our last target?
          IdentityComponent e = (IdentityComponent) em.getComponent(tgt.getCurrentTarget(), IdentityComponent.class);
          if(e != null){
            IdentityComponent me = em.getEntity(tgt);
            Entity i = me.getEntity();
            Entity them = e.getEntity();
            if(them != null && i != null){
              //update our target positin (ev. used by others), ev. rotation to target in positioning system
              tgt.pos = them.getLocalTranslation().clone();
            }
          }
        }
        //
        // ENDOF NPC UPDATE
      } else {
        //----------- target changed to new target -----------
        if(tgt.getCurrentTarget() != tgt.getLastTarget()){ 
          //
          // PLAYER UPDATE
            //----------- remove last marked -----------
            if(tgt.getLastTarget() != TargetComponent.NO_TARGET){
              log.fine("Player target changed, removing Selection on:"+tgt.getLastTarget());
              //target was set to a new entity
              //get visual and REMOVE selection from it
              VisualComponent vis = (VisualComponent) em
                .getComponent(tgt.getLastTarget(), VisualComponent.class);
              if(vis!=null){
                if (vis.vis != null) {
                  ((VisibleModel) vis.vis).removeSelectionMarker();
                  log.finest("Player target changed, Selection removed:"+tgt.getLastTarget());
                } else {
                  log.severe("Player target changed, Selection VIS not found on:"+tgt.getLastTarget());
                }
              } else
                log.severe("Player target changed, Selection NO VIS not found on:"+tgt.getLastTarget());

//FIXME this causes side effects with entity deletion, it seems, l2j deletes dead entities quite fast
//              LoggingComponent l = (LoggingComponent) em.getComponent(tgt.getLastTarget(), LoggingComponent.class);
//              if(l != null) {
//                Singleton.get().getPosSystem().removeComponentForUpdate(l);
//                em.removeComponent(tgt.getLastTarget(), l);
//              }
            }
            //----------- set current -----------
            if(tgt.hasTarget()){
              log.fine("Player target changed, adding Selection on:"+tgt.getCurrentTarget());
              //target was set to a new entity
              //get visual and add selection to it
              VisualComponent vis = (VisualComponent) em
                .getComponent(tgt.getCurrentTarget(), VisualComponent.class);
              if (vis != null && vis.vis != null) {
                ((VisibleModel) vis.vis).addSelectionMarker(tgt.color);
                log.fine("Player target changed, Selection added:"+tgt.getCurrentTarget());
              } else {
                log.severe("Player target changed, Selection VIS not found on on:"+tgt.getCurrentTarget());
              }

//FIXME this causes side effects with entity deletion, it seems, l2j deletes dead entities quite fast             
//              LoggingComponent l = (LoggingComponent) em.getComponent(tgt.getCurrentTarget(), LoggingComponent.class);
//              if(l == null){
//                l = new LoggingComponent();
//                em.addComponent(tgt.getCurrentTarget(), l);
//                Singleton.get().getPosSystem().addComponentForUpdate(l);
//              } else {
//                log.severe("Logging comp still on changed ent!!?");
//              }
            } else {
              //reset target creation by setting old target to current
              tgt.setNoTarget();
              tgt.pos = Vector3f.ZERO;
              log.fine("Player target changed, set to NOTARGET");
            }
          //----------- reset targeting creation changes by setting old target to current -----------
          tgt.setTarget(tgt.getCurrentTarget());
          log.fine("Player target changed, setting last to current, current to current target");
        } else {
          //check if target is set and moved out of distance
          if(!tgt.hasTarget())
            return;
          //TODO distance check only on client side? server still has our last target?
          IdentityComponent e = (IdentityComponent) em.getComponent(tgt.getCurrentTarget(), IdentityComponent.class);
          if(e != null){
            IdentityComponent me = em.getEntity(tgt);
            Entity i = me.getEntity();
            Entity them = e.getEntity();
            if(them != null && i != null){
              //update our target positin (ev. used by others)
              tgt.pos = them.getLocalTranslation();
//              if(tgt.pos.distance(i.getLocalTranslation()) > MAX_TARGETING_DISTANCE) {
//                //remove next time in above code
//                tgt.setNoTarget();
//              } else {
                //update health bar of highlighted target
                VisualComponent vis = (VisualComponent) em
                    .getComponent(tgt.getCurrentTarget(), VisualComponent.class);
                if (vis != null && vis.vis != null) {
                  ((VisibleModel) vis.vis).updateHealthbar((float)l2j.l2jEntity.getCurrentHp()/(float)l2j.l2jEntity.getMaxHp());
                }else
                  log.severe("Player target changed, VIS not found on :"+tgt.getCurrentTarget()+" for HealthBar update");
//              }
              //update target information for environment
              EnvironmentComponent env = (EnvironmentComponent) Singleton.get().getEntityManager().getComponent(i.getId(), EnvironmentComponent.class);
              if (env != null) {
                env.changed = true;
                log.finer("Should update stance");
              } else
                log.severe("No EnvironmentComponent found with entity id "
                        + i.getId() + ", perhaps just create one?");
            } else {
              //remove next time in above code
              tgt.setNoTarget();
            }
          } else {
            //remove next time in above code
            tgt.setNoTarget();
          }
        }
      }
      //
      // END OF PLAYER UPDATE
    } else
      if(c instanceof PositioningComponent){
        PositioningComponent com = (PositioningComponent) c;
        IdentityComponent e = em.getEntity(com);
        if(e != null)
        {
          Entity ent = e.getEntity();
          ent.setLocalTranslation(com.position.x, com.position.y+com.heightOffset, com.position.z);
          ent.setLocalRotation(new Quaternion().fromAngleNormalAxis(com.heading, Vector3f.UNIT_Y.negate()));
        } else {
          log.severe("Positioning component without identity component found! comp:"+
              c+" at "+ com.position.x+ ", "+(com.position.y+com.heightOffset)+", "+com.position.z);
          //FIXME this is a workaround, investigate why this can happen! was it added twice? should we better use a hasmap for components
          dumpComponents();
          System.out.println("----- now em ----------");
          em.dumpComponents(em.getEntityId(c));
          em.dumpAllComponents();
          removeComponentForUpdate(com);
        }
//    }else
//      if(c instanceof SimplePositionComponent){
//        SimplePositionComponent com = (SimplePositionComponent) c;
View Full Code Here


  }
 
  //FIXME this is a copy from NPCHandler move this out to the entity Manager !!
  public Entity createPCComponents(EntityData e, VisibleModel visible) {
   
    EntityManager em = Singleton.get().getEntityManager();
    final Entity ent = em.createEntity(e.getObjectId());
    PositioningComponent pos = new PositioningComponent();
    L2JComponent l2j = new L2JComponent();
    VisualComponent vis = new VisualComponent();
    EnvironmentComponent env = new EnvironmentComponent();
    TargetComponent tgt = new TargetComponent();
    LoggingComponent log = new LoggingComponent();
   
    em.addComponent(ent.getId(), env);
    em.addComponent(ent.getId(), l2j);
    em.addComponent(ent.getId(), pos);   
    em.addComponent(ent.getId(), vis);
    em.addComponent(ent.getId(), tgt);
    em.addComponent(ent.getId(), log);
       
    //done here extra as in update values will be left untouched
    pos.startPos.set(e.getX(), e.getY(), e.getZ());
    pos.position.set(pos.startPos);
    pos.goalPos.set(pos.position);
    pos.walkSpeed = e.getWalkSpeed();
    pos.runSpeed = e.getRunSpeed();
    pos.running = e.isRunning();
    pos.heading = e.getHeading();
    pos.targetHeading = pos.heading;
    pos.teleport = true;
   
    vis.vis = visible;
    visible.attachVisuals();
   
    l2j.isPlayer  = true;
    em.setPlayerId(ent.getId());
    l2j.l2jEntity = e;

    ent.setLocalTranslation(pos.position);
    ent.setLocalRotation(new Quaternion().fromAngleAxis(e.getHeading(), Vector3f.UNIT_Y));
    ent.attachChild(visible);
View Full Code Here

  }


  private void createNpc(NpcData e) {
   
    EntityManager em = Singleton.get().getEntityManager();
    PositioningComponent pos = new PositioningComponent();
    L2JComponent l2j = new L2JComponent();
    VisualComponent vis = new VisualComponent();
    EnvironmentComponent env = new EnvironmentComponent();
    //FIXME parallel create problems, synchronize creation and essential components or at least create/check of components
System.out.println("createNpc pre createEntity "+e.getObjectId());
    Entity ent = em.createEntity(e.getObjectId());
System.out.println("createNpc post createEntity "+e.getObjectId());
    em.addComponent(ent.getId(), pos);
System.out.println("createNpc post Add pos "+e.getObjectId());
    em.addComponent(ent.getId(), vis);
    System.out.println("createNpc post Add vis "+e.getObjectId());
    em.addComponent(ent.getId(), env);
    System.out.println("createNpc post Add env "+e.getObjectId());
    em.addComponent(ent.getId(), l2j);
    System.out.println("createNpc post Add l2j "+e.getObjectId());
   
    updateComponents(e, ent, pos, l2j, env, vis);//vis might take some time so we already added pos for updates
    System.out.println("createNpc end  "+e.getObjectId());
View Full Code Here

  {
    log.fine("Read from Server "+this.getClass().getSimpleName());
    int id = readD();
    int color = readH();
    //writeD(0x00);
    EntityManager em = Singleton.get().getEntityManager();
    int pID = _client.getCharHandler().getSelectedObjectId();
    TargetComponent tc = (TargetComponent) em.getComponent(pID, TargetComponent.class);
    if(tc != null){
      tc.setTarget(id);
      tc.color = toColorRGBA(color);
    }
    PositioningComponent pcpos = (PositioningComponent) em.getComponent(pID, PositioningComponent.class);
    PositioningComponent npcpos = (PositioningComponent) em.getComponent(id, PositioningComponent.class);
    if(pcpos != null && npcpos != null){
      pcpos.targetHeading = PositioningSystem.getHeading(pcpos.position, npcpos.position);
      //npcpos.targetHeading = PositioningSystem.getHeading(npcpos.position, pcpos.position);
System.out.println("MyTargetSelected: Set targetheading for "+pID+" to "+pcpos.targetHeading+" looking at "+id);     
    }
View Full Code Here

//    Vector3f tPos = new Vector3f();
//    readD();//x
//    readD();//y
//    readD();//z
//    readD();//0x00
    EntityManager em = Singleton.get().getEntityManager();
    TargetComponent tc = (TargetComponent) em.getComponent(id, TargetComponent.class);
    tc.setTarget(TargetComponent.NO_TARGET);
    tc.color = null;
    EnvironmentComponent env = (EnvironmentComponent) em.getComponent(id, EnvironmentComponent.class);
    if (env != null){
      env.changed = true;
    }else
      log.severe("No EnvironmentComponent found with entity id "+id+", perhaps just create one?");
  }
View Full Code Here

  public void handlePacket() {
    log.fine("Read from Server "+this.getClass().getSimpleName());
    int whoAttacked = readD();
    log.finer("AUTOATTACK STARTED by+"+whoAttacked);
    //face at target
    EntityManager em = Singleton.get().getEntityManager();
    PositioningComponent pcpos = (PositioningComponent) em.getComponent(whoAttacked, PositioningComponent.class);
    TargetComponent tc = (TargetComponent) em.getComponent(whoAttacked, TargetComponent.class);
    PositioningComponent npcpos = null;
    if(tc!=null && tc.hasTarget()) {
      log.finer("AUTOATTACK STARTED by+"+whoAttacked+" target comp :"+tc.getCurrentTarget());
      npcpos = (PositioningComponent) em.getComponent(tc.getCurrentTarget(), PositioningComponent.class);

      if(pcpos != null && npcpos != null){
        pcpos.targetHeading = PositioningSystem.getHeading(pcpos.position, npcpos.position);
System.out.println("AutoAttackStart: Set heading for "+whoAttacked+" to "+pcpos.targetHeading+" looking at "+tc.getCurrentTarget());       
      }
View Full Code Here

    //player receives an own my target selected in addition so we drop this
    int pID = _client.getCharHandler().getSelectedObjectId();
    if(id != pID){
      //TODO what should we do in this message which just says id starts targeting tgt
      _client.getChatHandler().receiveMessage(id,0 /*all*/,Integer.toString(id),"I see you baggard! <"+target+">");
      EntityManager em = Singleton.get().getEntityManager();
      TargetComponent tc = (TargetComponent) em.getComponent(id, TargetComponent.class);
      if(tc != null){
        tc.setTarget(target);
      }
      PositioningComponent pcpos = (PositioningComponent) em.getComponent(target, PositioningComponent.class);
      PositioningComponent npcpos = (PositioningComponent) em.getComponent(id, PositioningComponent.class);
      if(pcpos != null && npcpos != null){
        //pcpos.targetHeading = PositioningSystem.getHeading(pcpos.position, npcpos.position);
        npcpos.targetHeading = PositioningSystem.getHeading(npcpos.position, pcpos.position);
System.out.println("TargetSelected: Set heading for "+id+" to "+npcpos.targetHeading+" looking at "+target);
      }
      EnvironmentComponent env = (EnvironmentComponent) em.getComponent(id, EnvironmentComponent.class);
      if (env != null){
        env.changed = true;
      }else
        log.severe("No EnvironmentComponent found with entity id "+id+", perhaps just create one?");
    }
View Full Code Here

        if(readD()>0) whereTo = 5;//fixed or festival
        if(readD()>0) whereTo = 3;//fort
      //signal animation death
        Singleton.get().getAnimSystem().callAction(CallActions.Die, id);
     
      EntityManager ent = Singleton.get().getEntityManager();
      //update health properly
      L2JComponent com = (L2JComponent) ent.getComponent(id, L2JComponent.class);
      com.l2jEntity.setCurrentHp(0);
     
      //player died
      int playerId = _client.getCharHandler().getSelectedObjectId();
        if(id == playerId) {
          Singleton.get().getGuiController().displayReviveJPanel(whereTo, null);
        } else { //target died?
          TargetComponent tgt = (TargetComponent) ent.getComponent(playerId, TargetComponent.class);
          if(tgt.getCurrentTarget() == id){
            //remove it and signla env change
            tgt.setNoTarget();
            EnvironmentComponent env = (EnvironmentComponent) ent.getComponent(playerId, EnvironmentComponent.class);
            env.changed = true;
           
          }
        }
  }
View Full Code Here

    readD();//writeD(_ty);
    readD();//writeD(_tz);
  }

  private void updateComponents(int attack, int defend, int damage, int type){
    EntityManager em = Singleton.get().getEntityManager();
    EnvironmentComponent com = (EnvironmentComponent) em.getComponent(attack, EnvironmentComponent.class);
    if(com != null){
      com.damageDealt += damage;
      com.damageDealtType  |= type;
      com.changed = true
      Singleton.get().getAnimSystem().callAction(CallActions.DefaultAttack, attack);
    }
    com = (EnvironmentComponent) em.getComponent(defend, EnvironmentComponent.class);
    if(com != null){
      com.damageReceived += damage;
      com.damageReceivedType  |= type;
      com.changed = true;
      if(damage > 0)
View Full Code Here

TOP

Related Classes of com.l2client.controller.entity.EntityManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.