• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HealthData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongepowered.api.data.manipulator.mutable.entity.HealthData的典型用法代码示例。如果您正苦于以下问题:Java HealthData类的具体用法?Java HealthData怎么用?Java HealthData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HealthData类属于org.spongepowered.api.data.manipulator.mutable.entity包,在下文中一共展示了HealthData类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: rollback

import org.spongepowered.api.data.manipulator.mutable.entity.HealthData; //导入依赖的package包/类
@Override
public ActionableResult rollback() throws Exception {
    DataView entityData = formatEntityData();

    Optional<EntitySnapshot> snapshot = Prism.getGame().getRegistry().createBuilder(Builder.class).build(entityData);
    if (!snapshot.isPresent()) {
        return ActionableResult.skipped(SkipReason.INVALID);
    }

    Optional<Entity> entity = snapshot.get().restore();
    if (!entity.isPresent()) {
        return ActionableResult.skipped(SkipReason.INVALID);
    }

    // Don't let it burn to death (again?)
    entity.get().get(IgniteableData.class).ifPresent(data -> entity.get().offer(data.fireTicks().set(0)));

    // Heal, it was probably killed.
    entity.get().get(HealthData.class).ifPresent(data -> entity.get().offer(data.health().set(data.maxHealth().get())));

    return ActionableResult.success(new Transaction<>(new SerializableNonExistent(), entity.get()));
}
 
开发者ID:prism,项目名称:Prism,代码行数:23,代码来源:EntityResult.java


示例2: HealthDataView

import org.spongepowered.api.data.manipulator.mutable.entity.HealthData; //导入依赖的package包/类
public HealthDataView(HealthData value) {
    super(value);

    this.current = value.health().get();
    this.max = value.maxHealth().get();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:7,代码来源:HealthDataView.java


示例3: executeSkill

import org.spongepowered.api.data.manipulator.mutable.entity.HealthData; //导入依赖的package包/类
public SkillResult executeSkill(IActiveCharacter character, ExtendedSkillInfo esi) {
	if (esi == null)
		return SkillResult.FAIL;
	int level = esi.getTotalLevel();
	if (level < 0)
		return SkillResult.NEGATIVE_SKILL_LEVEL;
	level += characterService.getCharacterProperty(character, DefaultProperties.all_skills_bonus);
	Long aLong = character.getCooldowns().get(esi.getSkill().getName());
	long servertime = System.currentTimeMillis();
	if (aLong != null && aLong > servertime) {
		Gui.sendCooldownMessage(character, esi.getSkill().getName(), ((aLong - servertime) / 1000.0));
		return SkillResult.ON_COOLDOWN;
	}
	SkillData skillData = esi.getSkillData();
	SkillSettings skillSettings = skillData.getSkillSettings();
	float requiredMana = skillSettings.getLevelNodeValue(SkillNodes.MANACOST, level);
	float requiredHp = skillSettings.getLevelNodeValue(SkillNodes.HPCOST, level);
	SkillPrepareEvent event = new SkillPrepareEvent(character, requiredHp, requiredMana);
	game.getEventManager().post(event);
	if (event.isCancelled())
		return SkillResult.FAIL;
	double hpcost = event.getRequiredHp() * characterService.getCharacterProperty(character, DefaultProperties.health_cost_reduce);
	double manacost = event.getRequiredMana() * characterService.getCharacterProperty(character, DefaultProperties.mana_cost_reduce);
	//todo float staminacost =
	if (character.getHealth().getValue() > hpcost) {
		if (character.getMana().getValue() >= manacost) {
			SkillResult result = esi.getSkill().onPreUse(character);
			if (result == SkillResult.CANCELLED)
				return SkillResult.CANCELLED;
			if (result == SkillResult.OK) {
				float newCd = skillSettings.getLevelNodeValue(SkillNodes.COOLDOWN, level);
				SkillPostUsageEvent eventt = new SkillPostUsageEvent(character, hpcost, manacost, newCd);
				game.getEventManager().post(eventt);
				if (!event.isCancelled()) {
					double newval = character.getHealth().getValue() - eventt.getHpcost();
					if (newval <= 0) {
						//todo kill the player ?
						HealthData healthData = character.getPlayer().getHealthData();
					} else {
						character.getHealth().setValue(newval);
						newCd = eventt.getCooldown() * characterService.getCharacterProperty(character, DefaultProperties.cooldown_reduce);
						character.getMana().setValue(character.getMana().getValue() - event.getRequiredMana());
						long cd = (long) newCd;
						character.getCooldowns().put(esi.getSkill().getName(), cd + servertime);
						Gui.displayMana(character);
						return SkillResult.OK;
					}
				}
			}
		}
		return SkillResult.NO_MANA;
	}
	return SkillResult.NO_HP;
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:55,代码来源:SkillService.java


示例4: onEntitySpawn

import org.spongepowered.api.data.manipulator.mutable.entity.HealthData; //导入依赖的package包/类
@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
  List<Entity> entities = event.getEntities();

  Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
  for (Entity entity : entities) {
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);

    if (!optLevel.isPresent()) {
      continue;
    }
    int level = optLevel.get();

    if (entity instanceof Egg && optBlockCause.isPresent()) {
      PrimedTNT explosive = (PrimedTNT) entity.getLocation().getExtent().createEntity(
          EntityTypes.PRIMED_TNT,
          entity.getLocation().getPosition()
      );

      explosive.setVelocity(entity.getVelocity());
      explosive.offer(Keys.FUSE_DURATION, 20 * 4);

      // TODO used to have a 1/4 chance of creating fire
      entity.getLocation().getExtent().spawnEntity(
          explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.DISPENSE).build()).build()
      );

      event.setCancelled(true);
      return;
    }

    if (level > 1) {
      // TODO move damage modification
      if (entity instanceof Monster) {
        HealthData healthData = ((Monster) entity).getHealthData();
        double curMax = healthData.maxHealth().get();

        if (curMax <= 80) { // TODO do this a better way, but for now it prevents super mobs

          double newMax = curMax * getHealthMod(level);

          healthData.set(Keys.MAX_HEALTH, newMax);
          healthData.set(Keys.HEALTH, newMax);

          entity.offer(healthData);
        }

        // Wandering Bosses
        Collection<String> wanderers = wanderingMobManager.getSupportedWanderersOfType(entity.getType());
        for (String wanderer : wanderers) {
          if (wanderingMobManager.chanceBind(wanderer, level, entity)) {
            break;
          }
        }
      }
    }

    Optional<Value<Integer>> optExplosiveRadius = Optional.empty();
    // Optional<Value<Integer>> optExplosiveRadius = event.getEntity().getValue(Keys.EXPLOSIVE_RADIUS);

    if (optExplosiveRadius.isPresent()) {
      Value<Integer> explosiveRadius = optExplosiveRadius.get();
      int min = explosiveRadius.get();

      entity.offer(
          Keys.EXPLOSION_RADIUS,
          Optional.of(MathExt.bound((min + level) / 2, min, entity instanceof Fireball ? 4 : 9))
      );
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:73,代码来源:WildernessWorldWrapper.java


示例5: setAmount

import org.spongepowered.api.data.manipulator.mutable.entity.HealthData; //导入依赖的package包/类
@Override
public void setAmount(double amount) {
    HealthData data = this.getHandle().getOldData();
    data.health().set(getHandle().getOldData().health().get() + amount);
    getHandle().setNewData(data);
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:7,代码来源:PoreEntityRegainHealthEvent.java



注:本文中的org.spongepowered.api.data.manipulator.mutable.entity.HealthData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DelayMeta类代码示例发布时间:2022-05-22
下一篇:
Java TranslateOption类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap