Armor Item improvements (& other misc)

TODO: Make option to return to previewing with dummy
This commit is contained in:
Kae 2023-08-18 18:06:00 +10:00
parent aa0ef06ac6
commit 0c2015118b
7 changed files with 90 additions and 31 deletions

View File

@ -939,28 +939,55 @@ Humanoid Humanoid::makeDummy(Gender gender) {
return humanoid;
}
List<Drawable> Humanoid::renderDummy(Gender gender, HeadArmor const* head, ChestArmor const* chest, LegsArmor const* legs, BackArmor const* back) {
List<Drawable> Humanoid::renderDummy(Gender gender, Maybe<HeadArmor const*> head, Maybe<ChestArmor const*> chest, Maybe<LegsArmor const*> legs, Maybe<BackArmor const*> back) {
if (head) {
setHeadArmorFrameset(head->frameset(gender));
setHeadArmorDirectives(head->directives());
setHelmetMaskDirectives(head->maskDirectives());
if (auto headPtr = *head) {
setHeadArmorFrameset(headPtr->frameset(gender));
setHeadArmorDirectives(headPtr->directives());
setHelmetMaskDirectives(headPtr->maskDirectives());
}
else {
setHeadArmorFrameset("");
setHeadArmorDirectives("");
setHelmetMaskDirectives("");
}
}
if (chest) {
setBackSleeveFrameset(chest->backSleeveFrameset(gender));
setFrontSleeveFrameset(chest->frontSleeveFrameset(gender));
setChestArmorFrameset(chest->bodyFrameset(gender));
setChestArmorDirectives(chest->directives());
if (auto chestPtr = *chest) {
setBackSleeveFrameset(chestPtr->backSleeveFrameset(gender));
setFrontSleeveFrameset(chestPtr->frontSleeveFrameset(gender));
setChestArmorFrameset(chestPtr->bodyFrameset(gender));
setChestArmorDirectives(chestPtr->directives());
}
else {
setBackSleeveFrameset("");
setFrontSleeveFrameset("");
setChestArmorFrameset("");
setChestArmorDirectives("");
}
}
if (legs) {
setLegsArmorFrameset(legs->frameset(gender));
setLegsArmorDirectives(legs->directives());
if (auto legsPtr = *legs) {
setLegsArmorFrameset(legsPtr->frameset(gender));
setLegsArmorDirectives(legsPtr->directives());
}
else {
setLegsArmorFrameset("");
setLegsArmorDirectives("");
}
}
if (back) {
setBackArmorFrameset(back->frameset(gender));
setBackArmorDirectives(back->directives());
if (auto backPtr = *back) {
setBackArmorFrameset(backPtr->frameset(gender));
setBackArmorDirectives(backPtr->directives());
}
else {
setBackArmorFrameset("");
setBackArmorDirectives("");
}
}
auto drawables = render();

View File

@ -208,8 +208,8 @@ public:
static Humanoid makeDummy(Gender gender);
// Renders to centered drawables (centered on the normal image center for the
// player graphics), (in pixels, not world space)
List<Drawable> renderDummy(Gender gender, HeadArmor const* head = nullptr, ChestArmor const* chest = nullptr,
LegsArmor const* legs = nullptr, BackArmor const* back = nullptr);
List<Drawable> renderDummy(Gender gender, Maybe<HeadArmor const*> head = {}, Maybe<ChestArmor const*> chest = {},
Maybe<LegsArmor const*> legs = {}, Maybe<BackArmor const*> back = {});
Vec2F primaryHandPosition(Vec2F const& offset) const;
Vec2F altHandPosition(Vec2F const& offset) const;

View File

@ -382,7 +382,7 @@ void ItemDrop::updateTaken(bool master) {
targetPosition += m_overheadOffset;
auto rect = owningEntity->collisionArea();
if (!rect.isNull())
targetPosition[1] += rect.yMax() + 1.5;
targetPosition[1] += rect.yMax() + 1.5f;
else
targetPosition[1] += 1.5f;
}

View File

@ -1151,7 +1151,7 @@ ItemPtr Player::pickupItems(ItemPtr const& items) {
if (items->pickupSound().size()) {
m_effectsAnimator->setSoundPool("pickup", {items->pickupSound()});
float pitch = 1.f - ((float)items->count() / (float)items->maxStack()) * 0.5f;
m_effectsAnimator->setSoundPitchMultiplier("pickup", clamp(pitch * Random::randf(0.9f, 1.1f), 0.f, 2.f));
m_effectsAnimator->setSoundPitchMultiplier("pickup", clamp(pitch * Random::randf(0.8f, 1.2f), 0.f, 2.f));
m_effectsAnimator->playSound("pickup");
}
auto itemDb = Root::singleton().itemDatabase();

View File

@ -10,7 +10,7 @@
namespace Star {
ArmorItem::ArmorItem(Json const& config, String const& directory, Json const& data) : Item(config, directory, data) {
ArmorItem::ArmorItem(Json const& config, String const& directory, Json const& data) : Item(config, directory, data), SwingableItem(config) {
refreshStatusEffects();
m_effectSources = jsonToStringSet(instanceValue("effectSources", JsonArray()));
m_techModule = instanceValue("techModule", "").toString();
@ -36,6 +36,20 @@ StringSet ArmorItem::effectSources() const {
return m_effectSources;
}
List<Drawable> ArmorItem::drawables() const {
auto drawables = iconDrawables();
Drawable::scaleAll(drawables, 1.0f / TilePixels);
Drawable::translateAll(drawables, -handPosition() / TilePixels);
return drawables;
}
float ArmorItem::getAngle(float aimAngle) {
return -25.0f * Constants::deg2rad;
}
void ArmorItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {}
void ArmorItem::fireTriggered() {}
List<String> const& ArmorItem::colorOptions() {
return m_colorOptions;
}
@ -113,9 +127,9 @@ Directives const& HeadArmor::maskDirectives() const {
List<Drawable> HeadArmor::preview(PlayerPtr const& viewer) const {
Gender gender = viewer ? viewer->gender() : Gender::Male;
Humanoid humanoid = Humanoid::makeDummy(gender);
//Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, this);
//Humanoid humanoid = Humanoid::makeDummy(gender);
Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, this, nullptr, nullptr, nullptr);
}
ChestArmor::ChestArmor(Json const& config, String const& directory, Json const& data)
@ -158,9 +172,9 @@ String const& ChestArmor::backSleeveFrameset(Gender gender) const {
List<Drawable> ChestArmor::preview(PlayerPtr const& viewer) const {
Gender gender = viewer ? viewer->gender() : Gender::Male;
Humanoid humanoid = Humanoid::makeDummy(gender);
//Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, nullptr, this);
//Humanoid humanoid = Humanoid::makeDummy(gender);
Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, nullptr, this, nullptr, nullptr);
}
LegsArmor::LegsArmor(Json const& config, String const& directory, Json const& data)
@ -182,9 +196,9 @@ String const& LegsArmor::frameset(Gender gender) const {
List<Drawable> LegsArmor::preview(PlayerPtr const& viewer) const {
Gender gender = viewer ? viewer->gender() : Gender::Male;
Humanoid humanoid = Humanoid::makeDummy(gender);
//Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, nullptr, nullptr, this);
//Humanoid humanoid = Humanoid::makeDummy(gender);
Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, nullptr, nullptr, this, nullptr);
}
BackArmor::BackArmor(Json const& config, String const& directory, Json const& data)
@ -206,8 +220,8 @@ String const& BackArmor::frameset(Gender gender) const {
List<Drawable> BackArmor::preview(PlayerPtr const& viewer) const {
Gender gender = viewer ? viewer->gender() : Gender::Male;
Humanoid humanoid = Humanoid::makeDummy(gender);
//Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
//Humanoid humanoid = Humanoid::makeDummy(gender);
Humanoid humanoid = viewer ? *viewer->humanoid() : Humanoid::makeDummy(gender);
return humanoid.renderDummy(gender, nullptr, nullptr, nullptr, this);
}

View File

@ -6,7 +6,7 @@
#include "StarStatusEffectItem.hpp"
#include "StarEffectSourceItem.hpp"
#include "StarPreviewableItem.hpp"
#include "StarSwingableItem.hpp"
namespace Star {
STAR_CLASS(ArmorItem);
@ -15,7 +15,7 @@ STAR_CLASS(ChestArmor);
STAR_CLASS(LegsArmor);
STAR_CLASS(BackArmor);
class ArmorItem : public Item, public StatusEffectItem, public EffectSourceItem {
class ArmorItem : public Item, public EffectSourceItem, public SwingableItem {
public:
ArmorItem(Json const& config, String const& directory, Json const& data);
virtual ~ArmorItem() {}
@ -23,6 +23,13 @@ public:
virtual List<PersistentStatusEffect> statusEffects() const override;
virtual StringSet effectSources() const override;
virtual List<Drawable> drawables() const override;
virtual float getAngle(float aimAngle) override;
virtual void fire(FireMode mode, bool shifting, bool edgeTriggered) override;
virtual void fireTriggered() override;
List<String> const& colorOptions();
Directives const& directives() const;

View File

@ -337,6 +337,14 @@ BeamMiningTool::BeamMiningTool(Json const& config, String const& directory, Json
m_blockVolume = assets->json("/sfx.config:miningBlockVolume").toFloat();
m_endType = EndType::Object;
if (auto jRate = instanceValue("scaleRate")) {
if (jRate.canConvert(Json::Type::Float)) {
float rate = jRate.toFloat();
m_tileDamage /= rate;
m_cooldownTime /= rate;
}
}
m_inhandStatusEffects = instanceValue("inhandStatusEffects", JsonArray()).toArray().transformed(jsonToPersistentStatusEffect);
}
@ -359,7 +367,10 @@ List<PreviewTile> BeamMiningTool::preview(bool shifting) const {
if (ownerp && worldp) {
if (ownerp->isAdmin() || ownerp->inToolRange()) {
Vec3B light = Color::rgba(ownerp->favoriteColor()).toRgb();
Color lightColor = Color::rgba(ownerp->favoriteColor());
if (!ready())
lightColor *= Color::rgbaf(0.75f, 0.75f, 0.75f, 1.0f);
Vec3B light = lightColor.toRgb();
int radius = !shifting ? m_blockRadius : m_altBlockRadius;
for (auto pos : tileAreaBrush(radius, ownerp->aimPosition(), true)) {
if (worldp->tileIsOccupied(pos, TileLayer::Foreground, true)) {