美文网首页
实例:新建一个简单的完整游戏

实例:新建一个简单的完整游戏

作者: mudinhand | 来源:发表于2018-04-23 15:54 被阅读0次

Introduction: The Tutorial World

目标

  1. 有power, 值为1-10
  2. 命令setpower
  3. 命令attack, 生成1-10*power之间的数值
  4. 命令createNPC
  5. npc/cmd (name)=(command) 指挥npc执行command

添加power属性

# mygame/typeclasses/characters.py

from evennia import DefaultCharacter

class Character(DefaultCharacter):
    """
     [...]
    """
    def at_object_creation(self):
        "This is called when object is first created, only."   
        self.db.power = 1         
        self.db.combat_score = 1

加载与更新

evennia reload
@typeclass/force self
@examine self

角色生成

  • One character generation Command to set the "Power" on the Character.
  • A chargen CmdSet to hold this command. Lets call it ChargenCmdset.
  • A custom ChargenRoom type that makes this set of commands available to players in such rooms.
  • One such room to test things in.
    房间带了个命令,所以角色在这个房间可以执行,另一个房间不可以。

战斗系统

# announce
message = "%s +attack%s with a combat score of %s!"
caller.msg(message % ("You", "", combat_score))
caller.location.msg_contents(message % 
                                     (caller.key, "s", combat_score),
                                     exclude=caller)

NPC系统

from evennia import create_object
    
class CmdCreateNPC(Command):
    """
    create a new npc

    Usage:
        +createNPC <name>

    Creates a new, named NPC. The NPC will start with a Power of 1.
    """ 
    key = "+createnpc"
    aliases = ["+createNPC"]
    locks = "call:not perm(nonpcs)"
    help_category = "mush" 
    
    def func(self):
        "creates the object and names it"
        caller = self.caller
        if not self.args:
            caller.msg("Usage: +createNPC <name>")
            return
        if not caller.location:
            # may not create npc when OOC
            caller.msg("You must have a location to create an npc.")
            return
        # make name always start with capital letter
        name = self.args.strip().capitalize()
        # create npc in caller's location
        npc = create_object("characters.Character", 
                      key=name, 
                      location=caller.location,
                      locks="edit:id(%i) and perm(Builders);call:false()" % caller.id)
        # announce 
        message = "%s created the NPC '%s'."
        caller.msg(message % ("You", name)) 
        caller.location.msg_contents(message % (caller.key, name), 
                                                exclude=caller) 

相关文章

网友评论

      本文标题:实例:新建一个简单的完整游戏

      本文链接:https://www.haomeiwen.com/subject/vcmklftx.html