Git Product home page Git Product logo

Comments (17)

Nadorrano avatar Nadorrano commented on August 23, 2024

I proposed to use an equip handler to administrate character equipment. Something like this:

https://github.com/Nadorrano/ainneve/blob/master/world/equip.py

it's completely modulare and is attached to the main Character typeclass as a property. More info in the doc in the module.

related commands:

https://github.com/Nadorrano/ainneve/blob/master/commands/equip_commands.py

If you folks like this approach I can adapt it a little bit more

from ainneve.

whitenoiseoss avatar whitenoiseoss commented on August 23, 2024

Nadorrano,

I think this looks great. There is a little bit of refactoring that will probably be done, but overall this would be very useful and a good addition.

For this to be implemented we need:

  • Item typeclass
  • Weapon typeclass skeleton
  • Armor typeclass skeleton

On Item, lets have an on_hold method, and then we can save on_equip for a typeclass higher up that Weapon, Armor, Shield will receive. We could also have an on_wear. I would have to think about the hierarchy here a little bit. If you would like to make a proposal for the Typeclass hierarchy going from Object to Weapon/Armor/Shield, that would be good as well.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

The hierarchy is a delicate thing. Don't ask me, I like multiple inheritance and I have a tendency to overcomplicate things.

But why so many hooks are needed? Is not enough to have a single on_equip on the base Item typeclass that can be redefined appropriately on each child?

from ainneve.

whitenoiseoss avatar whitenoiseoss commented on August 23, 2024

An "Item" does not need an on_equip, because most of the things that will come from Item cannot be equipped (for example, a book or a potion). They likely can be held, however, which is a different event than equipping something. on_equip and on_wear could potentially be the same.

Also, yes, multiple inheritance is usually a bad practice. However, I think Shield may require multiple inheritance. When I wrote Shield before in my own module, it inherited both Weapon and Armor.

I will think over the hierarchy later today.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

My proposal:
to have on_hold and on_equip (maybe on_wield too) on the parent Item typeclass, both: pass.
Every child typeclass will overload needed methods and can be controlled by lock checks. Every hook is called by a different command hence they will strike independently. So you will get your hooks called correctly, if defined, when you wield your sword, or when you hold it in your hand, to be enchanted or something.
I thinked that a strict adhesion to classes is going to kill duck typing at some point, but I'm not an expert and I will wait for some better advice.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

Then we can simply derive Weapon and Shield from Item. And from these, more specific subclasses.

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

on_wield and on_hold seem the same to me from a world model point of view; of course the player interface may be hold, wield, etcetera but is there a use case for different game effects when wielding vs. holding something?

I think on_equip is OK on Item because a character conceivably can hold just about anything they can put in their inventory (a book, potion, etc.).

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

Ok, I will put something together in the next hours.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

Base item skeleton
https://github.com/Nadorrano/ainneve/blob/master/typeclasses/items.py
Equip Handler
https://github.com/Nadorrano/ainneve/blob/master/world/equip.py
Equip Commands
https://github.com/Nadorrano/ainneve/blob/master/commands/equip_commands.py

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

At the moment I put the hooks on the base Item, waiting for a better solution.
We have three hooks, at_hold, at_equip, at_remove. It should be enough, since every hook can access the character equip to check the state of the object and knows who is the character.
Slots, as a list, are loaded by the init function, not linked to the race yet, but some default slots are present.
At the moment three slots are hardcoded: 'left hand', 'right hand', 'holds', this is important since they are used by methods.
I made just one module for item, armor and weapons but it should be splitted, I think.

To equip an object:

  • obj must inherit from Item
  • obj must have db.slot == string or list of strings
  • character's equip and obj must have a slot in common
  • the slot must be empty (of course)
  • character access the equip lock check
  • character access the hold lock check to hold the object

To test:
@create a sword:items.Sword
wield sword
eq
remove sword

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

Sounds good.

Rereading @whitenoiseoss earlier comment about on_equip on item I realize I didn't see that he distinguished between equip and hold, which makes perfect sense. However I don't think we lose much by putting on_equip on Item.

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

If @whitenoiseoss has no more review for this PR I'd like to merge; I'll wait until tomorrow.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

Yep, I'm waiting for feedbacks. My pull request is #13 let's move there to comment the code.

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

Thanks for waiting @Nadorrano, I'm starting review myself and will comment on the PR.

edit: I've finished my comments, thanks Nadorrano! Let me know what you think about my suggestions.

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

@Nadorrano I should add that you may want to create a separate branch for this PR and resubmit; I'm not sure but I think Github will automatically add any future commits on your master branch to this PR, which you probably don't want. See http://codeinthehole.com/writing/pull-requests-and-other-good-practices-for-teams-using-github/

It allows you to submit multiple pull requests without confusion. The classical Github gotcha is to continue committing to a pull request branch after making the initial request. When these commits are pushed to the remote, they will become part of the original pull request which often ends up conflating unrelated functionality.

from ainneve.

Nadorrano avatar Nadorrano commented on August 23, 2024

@ergodicbreak Nice, I replied to comments. It is not clear to me if I have to create a branch from my fork or I have to fork a branch created by you... I'm a github newb so I'll read that article, thanks!

from ainneve.

ergodicbreak avatar ergodicbreak commented on August 23, 2024

@Nadorrano I'm a beginner to Github too but I think you create a branch, and then make a PR against the main Ainneve master.

from ainneve.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.