Author Topic: Need help determining best way of doing this..  (Read 3964 times)

Offline vexcesban

  • Acquaintance
  • *
  • Posts: 25
  • -Noobie Mud Admin-
    • View Profile
Need help determining best way of doing this..
« on: June 11, 2010, 07:56:14 pm »
Hi guys, I'm making system where players can socket their equipment with gems that drop randomly
off monsters in the world. These gems will increase stats on the items and they can have multiple
sockets, so i need to save them as a seperate file when they are socketed so it doesn't mess up
the original item. I'm trying to visualize the best way of doing this and figured I'd try to pick someone
elses brain. Currently my eq saves in an array of file names and then is restored by cloning everything
in said array when they log in. I would have a seperate save directory for socketed eq files. Here is my
idea:

- When a player sockets an item

  1 - record all the stats of the item including its file name
  2 - destruct the item
  3 - if its already a socketed item, remove the .c file
  4 - write .c file for new item
  5 - clone item to player

Improvement could come in steps 4-5, I currently have a random equipment system built by an
old coder. The way it works is It goes through one file "/w/wizard/randomeqfile.c", and restores
from text files with variables for all the stats ( 1 for each item the player has ). The system is
very buggy as pieces sometimes poof so its getting removed, and i want something more reliable
for my gem socketing system.

Any suggestions are appreciated!

Offline Sluggy

  • Friend
  • **
  • Posts: 91
    • View Profile
    • Stellarmass
Re: Need help determining best way of doing this..
« Reply #1 on: June 11, 2010, 11:24:24 pm »
I like this idea you have and I could think of a few ways of doing it but... I'm a little confused as to what <i>exactly</i> you are trying to accomplish. What are you saving as a separate file? The socketed version of the item that the player has in their inventory? Why don't you want to simply save the stat changes with the item? Is it that you want the player to be able to remove the gems at a later point?

Keep in mind, I'm thinking in terms of DiabloII-style sockets so maybe I'm not quite getting the picture. Clarify a bit and maybe I can bounce some ideas for you.
 :)

Offline vexcesban

  • Acquaintance
  • *
  • Posts: 25
  • -Noobie Mud Admin-
    • View Profile
Re: Need help determining best way of doing this..
« Reply #2 on: June 11, 2010, 11:32:32 pm »
Yes the socketing is kind of like diablo II, except in a text based game :)

Currently every piece of equipment or weapon has its own file,

ie: mob A drops dagger.c

when players kill mob A, it clones the dagger.c file.
when player logs out, it saves the path name from dagger.c to array of eq

  eq=({"weapon","d/cave/moba/obj/dagger.c","boots","w/myria/keep/violet.c"})

etc, so when they log back on it just clones all of those files to the player.

So if i just modify the dagger.c file, everyone that has one will get the changes.
Thus i need to have a seperate new file to save the changes added by socketing gems.

I am trying to figure out the most logical way of doing this, I run a mud as a hobby and
my coding background is not the greatest so I appreciate any suggestions! :)
« Last Edit: June 11, 2010, 11:37:11 pm by vexcesban »

Offline Sluggy

  • Friend
  • **
  • Posts: 91
    • View Profile
    • Stellarmass
Re: Need help determining best way of doing this..
« Reply #3 on: June 11, 2010, 11:51:38 pm »
Ah I see. So what mudlib are you using exactly?

I'm using DeadSouls and it has the rather handy feature that a persistence-save-object is inherited by most items. Basically, anything that inherits this can register which instance variables should be saved with it. When the player saves, a recursive check is done on all of their inventory. As it comes to each object it not only saves the name of the file to clone, it also saves the value of any variables that were registered. When the player logs back in, this system works in reverse as it clones each objects and then sets it's instance variables accordingly. Well, that's the basic gist of it anyway. I've never done much with the code, just come across it time to time. Perhaps your mudlib has a similar feature?

Offline quixadhal

  • BFF
  • ***
  • Posts: 642
    • View Profile
    • WileyMUD
Re: Need help determining best way of doing this..
« Reply #4 on: June 12, 2010, 12:45:57 am »
Being a noob, I don't know what I'm talking about but....

It sounds like you'd want to make a new inheritable for the socket code, so weapons that you want to have sockets (or be able to have sockets) could inherit the functions that deal with them, including overriding things like how much damage they do (since the socket version has to check what's in the sockets, etc).

That way, your item does the checks to see if a particular gem can be socketed (CanSocket, DoSocket, etc).  The gems can just be simple items.

When you socket a gem, you 'd check the item, and if all is well, add a property to it with the gem's details, destroying the actual gem object once completed.

That way, the prototype doesn't know anything about particular gems, but it knows how to use them and deal with them, but your actual dagger.c#73467 will be saved with a property describing the gem that's in it.

Someone who knows what they're doing can probably describe that better, but it's an idea.

I see no reason to have to muck about with generating .c files on the fly. :)

Offline vexcesban

  • Acquaintance
  • *
  • Posts: 25
  • -Noobie Mud Admin-
    • View Profile
Re: Need help determining best way of doing this..
« Reply #5 on: June 12, 2010, 09:07:51 pm »
Ah I will have to search the dead souls lib to see how this code works, because
saving the equipment is where my problem lies. I definetely want to avoid creating
more .c files, but i need something that is foolproof. Thanks for the heads up.

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Need help determining best way of doing this..
« Reply #6 on: June 13, 2010, 08:30:11 am »
I think you may want to put your "gem" objects inside weapons' inventories (Yeah, every single object has its own inventory); I don't remember if player's saving code goes recursively all on its own, storing what's contained in containers he carries, but there's a high chance it'll Just Work.

... okay, I guess you'll need to add a CanReceive() function to your main weapons inheritable (or maybe object inheritable) that checks if it's a gem and returns 1 in that case to allow the move into the weapon's inventory. By default only containers allow putting stuff in them.
« Last Edit: June 13, 2010, 08:45:50 am by Raudhrskal »
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...

Offline vexcesban

  • Acquaintance
  • *
  • Posts: 25
  • -Noobie Mud Admin-
    • View Profile
Re: Need help determining best way of doing this..
« Reply #7 on: June 20, 2010, 04:51:49 pm »
Just wanted to reply and say thanks for the input I just recoded how the equipment was saved and im doing great.